Google OA Interview Question: Longest Dictionary Word Formed From Given Letters

19 Views
No Comments

Given a dictionary of English words, preprocess it in a setup phase so future lookups can be very efficient.

Given 9 letters, where each occurrence can be used at most once and duplicate letters are allowed, find the longest dictionary word that can be formed from those letters.

This problem asks you to preprocess a dictionary so that later queries with 9 letters can be answered efficiently. Since each letter can be used at most once and duplicate letters are allowed, the key is to compare character frequencies rather than just sets of letters. A common approach is to store each dictionary word with its letter counts, then for a query, scan candidate words and keep the longest one that fits within the available counts. If multiple lookups are expected, preprocessing with hash maps, frequency signatures, or a trie can speed up repeated searches.

END
 0