How do you find all the anagrams in the dictionary.
Software QA/Tests Interview Questions from Microsoft
(Continued from previous question...)
How do you find all the anagrams in the dictionary.
Question:
How do you find all the anagrams in the dictionary.
maybe an answer:
1. Create a hash function that sorts the words in alphabetic order, we will use this for our hashing
2. For each word in the dictionary - use the above hash if there is no collision create a new entry, if there is a collision add the word to the list of values.
3. Ignore/remove all entries of size 1. Now we have the list of all anagrams.
maybe an answer2:
Assign first 26 prime numbers for a to z ...if you are also considering A to Z assign next set of prime numbers to them to..
so lets take an example of two words abc and cab
here, abc => (2*3*5)= 30 [a is alloted 2, b->3, c->5,d->7..so on...)
also, cab => (5*2*3) = 30...thus both these words are anagrams..
(Continued on next question...)
Other Interview Questions
|