Reported July 2026
Bloombergstring

Word Break II

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

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

The data structure behind this one is a hash set of dictionary words, paired with a memo map keyed by start index. Bloomberg reported Word Break II in July 2026, and if your OA invite is sitting there, expect this exact shape: split a string into dictionary words and return every sentence in lexicographic order. The input is tiny, s is at most 20 characters, so brute force looks tempting. It's still easy to fumble the ordering or the reuse rule. If you blank mid-assessment, StealthCoder runs invisibly on your desktop and gives you a working solution as a safety net.

The problem

Given a string s and an array of unique dictionary words wordDict, insert spaces into s so that every resulting token is a dictionary word.
Return every valid sentence in lexicographic order. A dictionary word may be reused any number of times.

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

Examples
Example 1
s = "catsanddog"
wordDict = ["cat","cats","and","sand","dog"]
return = ["cat sand dog","cats and dog"]
The string can be segmented as cat sand dog or cats and dog. The two sentences are returned in lexicographic order.
Example 2
s = "pineapplepenapple"
wordDict = ["apple","pen","applepen","pine","pineapple"]
return = ["pine apple pen apple","pine applepen apple","pineapple pen apple"]
All three sentences concatenate to pineapplepenapple, and dictionary words such as apple may be reused.
Example 3
s = "catsandog"
wordDict = ["cats","dog","sand","and","cat"]
return = []
No sequence of dictionary words concatenates to the entire string.

Constraints
1 <= s.length <= 20
1 <= wordDict.length <= 1000
1 <= wordDict[i].length <= 10
s and every wordDict[i] contain only lowercase English letters.
All strings in wordDict are unique.
The total length of all valid output sentences does not exceed 10^5.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Convert wordDict to a hash set. Then run DFS from index i, trying every end j from i+1 up to min(n, i+10), since words max out at 10 characters. If s[i:j] is in the set, recurse on j and prepend the word to each sentence returned. Memoize by start index so you don't rebuild the same suffix results again. Base case: when i equals n, return a list with one empty string, and handle the trailing space carefully. The usual pitfall is the space: join with a space only when the suffix result is non-empty. The other trap is the ordering. Lexicographic order on the full sentence needs a final sort, or iterate candidate words in sorted order and check the result. Sorting at the end is the safe move. If the DFS logic slips under time pressure, StealthCoder is the hedge on the live OA, reading the problem and handing you a clean version.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Word Break II 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. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

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

⏵ The honest play

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

Bloomberg reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Word Break II FAQ

How hard is Word Break II really?+

It's a LeetCode hard on paper, but with s at most 20 characters it plays like a medium. The logic is DFS plus memoization. Most people lose points on sentence formatting and ordering, not on the core idea.

What's the trick to solving it fast?+

Put the words in a hash set, recurse from each start index, and cache the list of sentences per index. Only try substrings up to length 10. Once memoized, each suffix gets solved once instead of repeatedly.

Do I need to sort the output?+

Yes. This version requires lexicographic order. Collect every sentence, then sort the final list once before returning. It's cheap given the output cap of 10^5 total characters, and it avoids subtle ordering bugs from the DFS traversal order.

Should I use DP or DFS with memo?+

DFS with memo is simpler here because you must return the actual sentences, not just a boolean. A bottom-up DP works too, storing sentence lists per index, but the top-down version is easier to write correctly under pressure.

How do I prep for this in 48 hours?+

Write it from scratch twice. First the plain recursion, then add the memo map. Test on catsandog for the empty result and pineapplepenapple for word reuse. Check your spacing logic on the base case, because that's where most bugs hide.

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

OA at Bloomberg?
Invisible during screen share
Get it