Reported November 2025
Bloombergbacktracking

Generate Wildcard Binary Strings

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

Bloomberg reported this one in November 2025, and it looks harder than it is. Strip the wording and it's just "enumerate every combination of choices at each ? position." That's backtracking, plain and simple. With length capped at 20, you're not hunting for a clever optimization. You're writing a clean recursion that emits strings in the right order. If you've got an OA coming, this is a warm-up disguised as a problem. StealthCoder sits invisibly on your screen as a safety net if your mind goes blank mid-assessment, but you should be able to write this one yourself after reading this page.

The problem

pattern contains 0, 1, and ?. Replace every wildcard independently with either 0 or 1 and return every resulting binary string in lexicographic order.

Function
expandWildcards(pattern: String) → String[]

Examples
Example 1
pattern = "01?0"
return = ["0100","0110"]
The one wildcard produces two strings.
Example 2
pattern = "0??0"
return = ["0000","0010","0100","0110"]
Two wildcards produce four strings.

Constraints
0 <= pattern.length <= 20.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is ordering. If you recurse left to right and always try '0' before '1' at each wildcard, the output comes out already in lexicographic order. No sorting needed. Build the string character by character with an index. Fixed characters get appended as-is, and each ? branches into two calls. When the index hits the end, push the built string. The common pitfall is mutating a string in place and forgetting to undo it, or sorting at the end when you don't have to. Another one is the empty pattern. Length 0 is allowed, so decide what to return. Following the recursion, an empty pattern yields one empty string, so the result is [""]. Check the expected output before assuming. Total work is 2^k strings for k wildcards, so up to about a million outputs. If you blank under the clock, StealthCoder is the hedge that can hand you the backtracking skeleton live.

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 Generate Wildcard Binary Strings 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

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

Generate Wildcard Binary Strings FAQ

What's the trick to Generate Wildcard Binary Strings?+

Backtracking with a fixed branch order. Walk the pattern left to right. Copy 0 and 1 as they are. At a ?, try 0 first, then 1. Because you always choose 0 before 1, results come out in lexicographic order without any sort step.

How hard is this Bloomberg OA question really?+

Easy to medium. There's no hidden algorithm. It's a standard recursion over a string with a two-way branch. Most candidates lose points on edge cases like the empty pattern or by sorting unnecessarily, not on the core idea.

What's the time and space complexity?+

Time is O(2^k * n), where k is the number of wildcards and n is the pattern length, since each output string costs n to build. Output space is the same order. With n up to 20, that's fine, so don't try to prune anything.

Do I need to sort the result?+

No. If you branch 0 before 1 at every ? while moving left to right, the output is already sorted lexicographically. Adding a sort is harmless but wasteful. Just make sure your recursion order is right, and verify against the 0??0 example.

How do I prepare for this in 48 hours?+

Write the recursive version from scratch twice, then try an iterative version that expands a list of partial strings. Test on an empty pattern, no wildcards, and all wildcards. That covers the edge cases this problem is likely to probe.

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