Re:Most common phone interview question at Google
by asdginioubnou on Saturday May 02, 2020 @09:30PM
(#23056200)
>Let's say there are M different characters in the alphabet and N different characters in the string.
I mean "N characters in the string", i.e. the string is length N. There won't be N different characters.
Re:Most common phone interview question at Google
by v_g on Saturday May 02, 2020 @07:57PM
(#23055838)
Interesting point. However, Alphabet is probably not the best example, Unicode perhaps? The upper bound in Unicode is ~ 1.1 Million, but still fixed
Re:Most common phone interview question at Google
by asdginioubnou on Saturday May 02, 2020 @08:50PM
(#23056051)
That doesn't make a difference asymptotically, though it obviously makes a big difference in practice.
(I guess, most precisely, we should define K to be min(M + 1, N). Then the first solution is O(K^2) and the second solution is O(K))
EDIT: I assumed the first solution would compare each character to the characters visited so far, i.e.
Maybe it's That would make it O(KN). Or O(N) if we treat the size of the alphabet as fixed.