Count Binary Substrings
A easy-tier problem at 66% community acceptance, tagged with Two Pointers, String. Reported in interviews at IBM and 4 others.
Count Binary Substrings is an easy two-pointer string problem that shows up in real OAs at IBM, Morgan Stanley, Salesforce, ByteDance, and J.P. Morgan. The acceptance rate sits around 66 percent, which sounds reassuring until you realize most people who submit a solution aren't thinking about the trick. The problem wants you to count contiguous groups of 0s and 1s that are equal in length and adjacent. It's deceptively simple on the surface, which is exactly why candidates stumble during the live assessment. If this problem hits your OA and you blank on the grouping pattern, StealthCoder solves it in seconds, invisible to the proctor.
Companies that ask "Count Binary Substrings"
Count Binary Substrings 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. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know.
Get StealthCoderThe naive approach is to check every possible substring for validity, which tanks your time complexity. The actual trick is to group consecutive identical characters and track group sizes, then walk through adjacent pairs and count how many valid substrings exist between them. Two pointers or a group-size array both work fine here, but most candidates initially try substring enumeration and run out of time. The pattern is straightforward once you see it: if group A has size 3 and group B has size 3, you get one valid substring. If group B has size 5, you still get one valid substring (the ones and zeros portions can be any size from 1 to min(A, B)). The real pressure is thinking clearly under interview conditions. StealthCoder is the hedge for the one problem you didn't drill, surfacing a working solution instantly.
Pattern tags
You know the problem.
Make sure you actually pass it.
Count Binary Substrings recycles across companies for a reason. It's easy-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. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Count Binary Substrings interview FAQ
Is Count Binary Substrings still asked at big tech companies?+
Yes. IBM, Morgan Stanley, Salesforce, ByteDance, and J.P. Morgan all report asking it. It's not a bleeding-edge algorithmic problem, but companies value it because it tests whether you can recognize a two-pointer grouping pattern under pressure, not just brute-force your way through.
What's the trick to solving this fast?+
Stop thinking about individual substrings. Group consecutive identical characters first, then iterate through adjacent group pairs. For each pair, the number of valid substrings is the minimum of their sizes. This reduces the problem from O(n-squared) enumeration to linear time.
How does the two-pointers approach differ from grouping?+
Grouping pre-computes group sizes in a first pass. Two pointers tracks group boundaries on the fly. Both hit O(n) time, but grouping is clearer to code and debug live. Two pointers saves space if that matters, which it rarely does at this difficulty level.
What do most candidates get wrong?+
They either iterate through every substring checking validity (too slow) or miscount valid pairs between adjacent groups. The second mistake is forgetting that if group A is 5 and group B is 3, you get exactly 3 valid substrings, not 8. Min(A, B) is the key insight.
Is this problem worth drilling before an OA?+
If you see two-pointer or string problems in your prep list, yes. The grouping pattern transfers to other interval-matching problems. But if you're short on time and haven't drilled it, the acceptance rate suggests you'll likely recognize the approach once you start. If you blank, you have a safety net.
Want the actual problem statement? View "Count Binary Substrings" on LeetCode →