Google Interview Question
Backend DevelopersCountry: United States
We can use Rabin Karp algorithm and generate hash for each possible sub-string using rolling hash. Using rolling hash reduces the complexity of generating hash since we will be reusing hash value of previous substring.
Add these to a map<hash, <start_index, length>>. So if we find to substrings with same hash and length then compare them. If they are equal then we have solution.
Wouldn't this be true if there are duplicates in the array and false otherwise?
- Tak904 March 01, 2018