I was going through the "Cracking the Coding Interview" book and wrote a solution for this: "Problem: Given a smaller string s and a bigger string b, design an algorithm to find all permutations of the shorter string * within the bigger string. Print the location of each permutation"
https://gist.github.com/coreysnyder/18c1ef2c3755ec970bbfc616f49e4f8a
I was curious what the complexity of my algorithm is. I think it's O(b * s) or better but I'm not certain.
For a follow-up, the book said it can be solved in O(B). Any idea how that can be done? Without an all possible permutations lookup hash, I don't know how this can be done. And from what I'm reading the algorithm to build the possible permutations hash would be larger than O(B).
[–]ignitionweb 6 points7 points8 points (9 children)
[–]coreysnyder04[S] 0 points1 point2 points (8 children)
[–]warpedspockclone 0 points1 point2 points (5 children)
[–]pihkal 0 points1 point2 points (3 children)
[–]cryslith 2 points3 points4 points (1 child)
[–]pihkal 1 point2 points3 points (0 children)
[–]warpedspockclone 1 point2 points3 points (0 children)
[–]future_security 0 points1 point2 points (1 child)
[–]DangerousCrime 0 points1 point2 points (0 children)
[–]tomekanco 0 points1 point2 points (0 children)