0

Need help/solution for the following interview question: From a folder containing several files whose contents are the english dictionary, return a string or strings that, between them, contain all 26 letters of the alphabet. Improve this for speed. Provide alternate ways of doing this.

All help is appreciated! Thanks very much!

Coder2013333
  • 139
  • 1
  • 9

2 Answers2

1
return 'abcdefghijklmnopqrstuvwxyz';

They never said you had to read the files.

Chris Laplante
  • 29,338
  • 17
  • 103
  • 134
0

I think the question is about an efficient trie. Look for a ternary search tree. It's a efficient space saving version of the original trie where each node has 26 leafs (like the alphabet). A simple trie can also be create from an array look for example here http://phpir.com/tries-and-wildcards/

Micromega
  • 12,486
  • 7
  • 35
  • 72
  • I am actually looking into the trie based solution. But I cannot find anything close to this question online so cannot be sure that was the solution they were looking for. I tried to implement it without a tree/trie and they made suggestions etc. but not once suggested/hinted at a tree/trie. What would be a good approach without a trie? – Coder2013333 Jul 26 '12 at 23:06
  • I don't think there is any but I give you a link about trie and arrays. I don't know what language they use but an array is similar to a hashmap. You can also use hashmaps for strings. Also you can look for suffix tree or suffix array. That would build all suffices from the dictionnary which is a bit closer to your question then my first answer (when you must return an alphabet). – Micromega Jul 26 '12 at 23:15