Reported September 2026
Amazondynamic programming

Word Break

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

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

The data structure that decides Word Break is a hash set, and Amazon reported this one in September 2026. If your OA invite lands in the next couple of days, this is a pattern worth locking in. You get a string and a dictionary, and you say whether the string splits into dictionary words, reusing words freely. It looks like a string problem. It's really a DP over prefixes with a set for fast lookups. Brute force blows up, and that's the trap. If you blank mid-assessment, StealthCoder runs invisibly as a safety net and hands you the solution on screen.

The problem

Given a string s and an array of distinct dictionary words wordDict, return true if s can be split into a sequence of one or more dictionary words.
A dictionary word may be reused any number of times.

Function
wordBreak(s: String, wordDict: String[]) → boolean

Examples
Example 1
s = "leetcode"
wordDict = ["leet","code"]
return = true
The string splits as leet + code.
Example 2
s = "applepenapple"
wordDict = ["apple","pen"]
return = true
The word apple is reused in apple + pen + apple.
Example 3
s = "catsandog"
wordDict = ["cats","dog","sand","and","cat"]
return = false
No sequence of dictionary words covers the entire string.

Constraints
1 <= s.length <= 300.
1 <= wordDict.length <= 1000.
1 <= wordDict[i].length <= 20.
s and every dictionary word contain only lowercase English letters.
All dictionary words are distinct.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Put the dictionary in a hash set. Then build a boolean array dp of length n+1, where dp[i] means the first i characters can be split into dictionary words. Set dp[0] to true. For each i, check every j less than i: if dp[j] is true and s[j:i] is in the set, set dp[i] to true and break. The answer is dp[n]. The constraints help you. Words are at most 20 characters, so only look back up to 20 positions from i, which cuts the work a lot. The common pitfall is plain recursion with no memo, which goes exponential on inputs like repeated a's with no match. Another miss is forgetting that words can be reused. Check example 3, catsandog, by hand: it fails because og has no match. If you freeze on the live OA, StealthCoder is the hedge that gives you this DP when your head goes empty.

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 Word Break 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

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as word break. If you have time before the OA, drill that.

⏵ The honest play

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

Amazon 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.

Word Break FAQ

How hard is Word Break really?+

It's a medium. The idea is short once you see it: dp over prefixes plus a set lookup. Candidates struggle because they start with recursion and never add memoization. If you can write the dp array and the inner loop, you're done in about ten lines.

What's the trick for Word Break?+

Define dp[i] as whether the first i characters are breakable. Set dp[0] to true. For each i, find a j where dp[j] is true and the substring from j to i is in the set. Return dp[n]. The hash set makes each check fast.

Why does my recursive solution time out?+

Without memoization you recompute the same suffixes over and over, which is exponential. Cache results by start index, or switch to bottom-up dp. Strings like a long run of the same letter with one bad ending are the classic killer case.

Can I speed up the inner loop?+

Yes. Every dictionary word is at most 20 characters, so for each i you only need to check j from i-20 up to i. You can also precompute the max word length from the dictionary. That keeps the work close to n times 20 substring checks.

How do I prepare for this in 48 hours?+

Write the bottom-up solution from scratch twice and trace example 3 by hand. Then try a trie or DFS with memo as a variant. Know why a set beats scanning a list. Amazon reported this in September 2026, so expect it or something close.

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

OA at Amazon?
Invisible during screen share
Get it