Google | Onsite | Pairs of Adjacent Subsequences | Hard
Anonymous User
1369

The question is construced as follows:

Suppose you're given a list of strings named L, i.e ["SAPTRADFBSF", "ADFASATWSD", ...] and a list of pair of strings named P i.e [("RAD", "SAT"), ... ] . We're concerned with finding the starting position (and index i and i + 1) where pairs in P lie in adjacent strings in L. For example "RAD", lies in "SAPTRADFBSF" starting from position 4 and "SAT" also lies in "ADFASATWSD" starting from position 4 as well so we return (4, 0, 1). Moreoever, more than 1 entry may exists for adjacent elements in L and a specific pair. Each pair in P has the same length. Find an efficient way to return a list of all such matchings, i.e return [(4, 0, 1), ...] and so on. Also disucss the time complexity of your algorithm

I found this question to be hard and had difficuilt coming up with a solution that was more efficient than O(n^4). The interviewer suggested that using Rabin-Karp would give the most efficient solution.

Comments (6)