The Shortest Completing Word interview question gives you a license plate string and a list of words. Find the shortest word in the list that contains all the letters in the license plate (ignoring digits, spaces, and case). If multiple words have the same minimum length and contain all required letters, return the first one. This is a letter frequency matching problem.
Google asks this problem because it tests character frequency counting, case-insensitive matching, and clean comparison logic. It validates that candidates can use a Counter (or frequency array) to check if one frequency map is a subset of another, and can handle the "first minimum" requirement correctly. The problem models text completion systems and keyword matching in autocomplete engines.
The pattern is frequency map comparison. Extract letters from the license plate (ignoring non-alphabetic characters), convert to lowercase, and build a frequency counter. For each word in the list, build a frequency counter of its letters. Check if the word's counter "covers" the license plate counter: for every letter in the license plate counter, the word must have at least as many occurrences. Track the shortest covering word; return the first one found when there are ties.
licensePlate = "1s3 PSt", words = ["step", "steps", "stripe", "stepple"].
Letters in plate (lowercase): s, p, s, t → frequency: {s:2, p:1, t:1}.
Return: "steps".
Counter(plate) directly without filtering non-letter characters.For the Shortest Completing Word coding problem, the hash table string interview pattern is the straightforward approach. Python's Counter makes frequency comparison elegant: all(word_counter[c] >= plate_counter[c] for c in plate_counter). Google interviewers use this as a 5-minute warm-up — solve it cleanly, then discuss follow-ups: "What if words can also contain digits?" or "How would you optimize for repeated license plate queries?" Practice Counter-based subset checking — it appears in anagram, scramble, and character containment problems throughout interview preparation.