Pergunta de entrevista da empresa Disqus

Write a Unix glob implementation in python. Globbing lets you use * for zero or more characters, ? for a single character, [] for a character range.

Resposta da entrevista

Sigiloso

4 de mai. de 2012

The key to this problem is recursion and avoiding quadratic complexities, so you need to convert your text into words and then compose those words into a trie (not tree) of indexed characters. You then traverse that trie, recursing as necessary, to produce a list of matching words and their indices into the original text. Note: I made the whole search corpus into a trie, and I shouldn't have for maximum points. I should have only trie-d the first three or four characters and used linear matching for the rest of the words into order to save on memory.

1