Pregunta de entrevista de Amazon

How to design a system for generating anagrams

Respuesta de la entrevista

Anónimo

17 ene 2013

Anagram means rearrange the words of the input to a word in a dictionary. So input is a word w and the dictionary Dict. Approach 1 - Use linear optimization formulation. Every word in Dict is encoded as a frequency vector of how often each letter appears. Example - Apple = where each entry represents how often a,b,c,d,e ... appears in the word. Now each word, w_i in the Dict is associated to a binary variable b_i. The input word is also encoded as a vector, called V_input The optimization formulation is: Max sum(b_i) given constraints below V_input = sum from i=1 to N ( b_i*w_i) The result will be a set of b_i's that represent the set of words that have precisely the set of letters of the input word. This solution is a binary integer program so has a complexity of 2^N which is HUGE. Other solution is just heuristic games...think for yourself people !!!!