Solution to Quora's Typeahead Search challenge problem