3 ms·
Another easy solution is to just make a histogram of characters in each word and to compare the histograms. Anyway, if anagram questions were all that were ask
by nilkn 13y ago
Another easy solution is to just make a histogram of characters in each word and to compare the histograms.
Anyway, if anagram questions were all that were asked in technical interviews, I really doubt we'd have so much critique and analysis here. I've never been asked such a simple question in any technical interview. The closest would be the first phone screen I had for a Google internship, which had (arguably) simpler questions (like raise one integer to an integer power efficiently) but there were like three or four of them that you had to get right.
- philwelch 13y agoThe anagram question is a phone screen question, yeah. I believe the histogram solution is better performing than sorting, because storing the histograms as hash tables is O(n) on both words while the sorting solution is O(nlogn).