Interview Question

Interview(Student Candidate) New York, NY

given a english dictionary, how will you store it to so

  that when you are given an input like "rat", you can fast output all the anagrams of the word "rat"(which are "art", "tar"and "rat")

Interview Answer

2 Answers


split the word into chars and store them in a hashset

Anonymous on Jun 9, 2014

hash map ,using <key,value> pair,with key sorted word, and values all the anagrams appeared.

Anonymous on Jun 9, 2014

Add Answers or Comments

To comment on this, Sign In or Sign Up.