Amazon Interview Question: Given a keyword (ex: "abc") a... | Glassdoor

Interview Question

Software Engineer Intern Interview(Student Candidate)

Given a keyword (ex: "abc") and a list of words (ex

 : "aabc", "cab", "ab"), write a function that will return all words in the list that are the same/anagrams of the keyword. In this case, "cab" would be the only word returned. Later changes to the function were added: numbers and symbols might be included in the words but were to be ignored ("ca2b" still matched "abc"), make the function not case sensitive ("A" == "a"), etc...

Interview Answer

1 Answer


First, I hashed the keyword, making the letter the key and the number of times it appears a value. I did the same thing to the words in the list, skipping words that weren't the same length as the keyword (removed once he added the condition to ignore numbers and symbols). There were also other optimizations added.
Also, if you use a hashmap or any data structure, be prepared to answer why you used it. (Runtime, etc)

Interview Candidate on Mar 2, 2014

Add Answers or Comments

To comment on this, Sign In or Sign Up.