Reported September 2026
Googlecounting

Longest Dictionary Word from Nine Letters

Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Google OA. Under 2s to a working solution.
Founder's read

The hinted pattern says dynamic programming, but this Google question from September 2026 reduces to something much simpler: a letter-count comparison. You get a list of words and nine letters, and you return the longest word those letters can build, earliest wins ties. If you're staring at the invite and wondering whether you need a DP table, you don't. It's counting, done once per word. Get the tie-break and the empty-string case right and you're through. StealthCoder sits invisibly on your screen during the live OA as a safety net if you blank on the details, but this one is very learnable tonight.

The problem

You are given an array of lowercase dictionary words words and a lowercase string letters containing exactly nine characters. Return the longest word that can be built using the characters in letters.
Each occurrence in letters may be used at most once, so repeated characters in a word require the same number of occurrences in letters. If several buildable words have the same maximum length, return the one that appears earliest in words. Return the empty string when no word can be built.

Function
longestWord(words: String[], letters: String) → String

Examples
Example 1
words = ["cat","bt","hat","tree"]
letters = "atachxxxx"
return = "cat"
Both cat and hat can be built and have length three. Because cat appears first, it wins the tie.
Example 2
words = ["hello","world","hold","owl"]
letters = "ollheabcd"
return = "hello"
The letters contain exactly the h, e, two ls, and o needed for hello.
Example 3
words = ["aaa","bb"]
letters = "abcdefghi"
return = ""
Neither word is buildable because the nine letters do not contain enough copies of its repeated character.

Constraints
1 <= words.length <= 100000.
1 <= words[i].length <= 100.
The sum of all word lengths is at most 1000000.
letters.length == 9.
words[i] and letters contain only lowercase English letters.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Count the characters in letters once into a 26-slot array. For each word, skip it immediately if its length is greater than 9 or not longer than your current best. Otherwise count its characters and check that every count is at most the matching slot in letters. If it passes, it becomes the new best. Because you only replace on strictly longer length, the earliest word wins ties automatically. The pitfall is using a set instead of counts, which breaks repeated letters like the two ls in hello. Another is replacing on greater-or-equal length, which flips the tie-break. Total work is linear in the sum of word lengths, which is at most 1000000, so it's fast. No DP is needed. If you freeze during the live OA, StealthCoder can hand you this counting loop, but the whole solution is about fifteen lines.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Longest Dictionary Word from Nine Letters cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Google's OA.

Google reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Longest Dictionary Word from Nine Letters FAQ

Is this Google question really dynamic programming?+

No. The hint is misleading. Nothing overlaps or builds on subproblems. It's frequency counting: compare each word's letter counts against the nine given letters. Treat it as an array or hash-table counting problem and you'll finish quickly.

What's the trick to handling repeated letters?+

Use counts, not sets. Build a 26-element array from letters, then for each word count its characters and make sure none exceeds the available count. That's how hello needs two ls while aaa fails against abcdefghi.

How do I get the tie-break right?+

Scan words in the given order and only update your best when a candidate is strictly longer. An equal-length buildable word later in the list never replaces the earlier one, so cat beats hat in Example 1 without extra logic.

What's the time complexity and will it pass the constraints?+

O(total characters across words), at most 1000000 operations plus 26 per word for the comparison. With up to 100000 words that's fine. Skipping words longer than 9 or no longer than your best makes it faster still.

How do I prepare for this in 48 hours?+

Write the counting solution from scratch twice. Test the three examples plus an empty result and a word longer than nine characters. Then do a few other frequency-count problems so the 26-slot array pattern is automatic.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Google.

OA at Google?
Invisible during screen share
Get it