Number of Good Binary Strings
A medium-tier problem at 52% community acceptance, tagged with Dynamic Programming. Reported in interviews at Expedia and 1 others.
Number of Good Binary Strings is a medium DP problem that shows up in assessments at Expedia and Citadel. The acceptance rate sits around 52%, which means half the candidates who attempt it either time out, miscount, or build the wrong recurrence. The trick is recognizing that you're not generating all binary strings; you're counting valid ones under a specific constraint pattern. Most people either brute-force every substring (too slow) or miss that the state space collapses with memoization. If this problem hits your live OA and you blank on the constraint structure, StealthCoder surfaces the working DP formulation in seconds, invisible to the proctor.
Companies that ask "Number of Good Binary Strings"
Number of Good Binary Strings is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage.
Get StealthCoderThe problem asks you to count binary strings of a given length that don't contain a specific 'bad' substring. The naive approach checks every possible string, which is exponential and pointless. The real move is dynamic programming: track how many valid strings you can build by considering each position and remembering which prefix you've matched against the bad pattern. Think of it like KMP state tracking, except you're counting paths instead of searching. Common failure: building the recurrence without thinking about what 'state' means (length built so far, or how much of the bad pattern you've matched). StealthCoder's value here is that the state definition itself isn't obvious from a first read, so if you're stuck on the modeling step during the assessment, you get an instant, proven solution.
Pattern tags
You know the problem.
Make sure you actually pass it.
Number of Good Binary Strings recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Number of Good Binary Strings interview FAQ
Is this actually a DP problem or can you brute force it?+
Brute force fails on larger lengths. With DP and memoization, you reduce the search space dramatically by reusing subproblems. The acceptance rate of 52% suggests many candidates try a naive exponential approach first and time out.
How does the bad substring constraint change the DP state?+
Instead of a simple 'count strings of length n', your state becomes '(current position, how much of the bad pattern have I matched so far)'. That second dimension is what makes the problem non-trivial and why the pattern isn't obvious on first sight.
Do Expedia and Citadel ask this the same way or different variants?+
Input data only confirms both companies ask it. The exact variant and length limits may differ between their assessments, so focus on the general DP structure, not memorizing one test case.
What's the most common mistake candidates make?+
Forgetting that you need to track partial matches against the bad pattern, not just the current string length. Without that state, your recurrence undercounts or overcounts valid strings.
Should I precompute something about the bad pattern before DP?+
Yes. Building a transition table or KMP-like failure function for the bad pattern helps you know which state to jump to when you append a '0' or '1'. Skipping this step makes the DP logic fragile.
Want the actual problem statement? View "Number of Good Binary Strings" on LeetCode →