3 ms·
phil already answered you, but to expand a bit, programmers are asked to do anagrams all the time. Except it is not 'does this word have the same letters as thi
by RogerL 13y ago
phil already answered you, but to expand a bit, programmers are asked to do anagrams all the time. Except it is not 'does this word have the same letters as this other word, just perhaps in different order', it is "is this list of address the same as this other list?" or what have you. In other words, do two differently ordered sets of items contain the same items? Asking the problem as an anagram just reduces it down to its essence. And, like it or not, there is an important efficiency issue here. The decent solution will be a bit slow compared to the optimal solution, and sometimes that can be important. The naive solution will not work for anything but toy cases. But, you can set the bar for the follow on discussion according to the kind of work you do.
I'm not sure if I think it is a great interview question or not, but it gives the interviewer a chance to see if you can do something basic in your language, and then it opens the discussion to broader contexts where you don't have to code - efficiency concerns if these are string or emails, but 1MB documents, or dealing with Unicode, terminations of strings and so on, algorithm performance, and so on.