Minimum Deletions to Make String Balanced
A medium-tier problem at 66% community acceptance, tagged with String, Dynamic Programming, Stack. Reported in interviews at redbus and 0 others.
Minimum Deletions to Make String Balanced is a medium-difficulty string problem that shows up on assessments when companies want to see if you can think beyond greedy. The acceptance rate sits at 65 percent, which sounds high until you realize most candidates either brute-force it inefficiently or miss the optimal DP insight entirely. RedBus has asked this one. It's the kind of problem that feels simple at first read, then punishes you in the live OA if you haven't locked down the pattern. If this hits your assessment and you blank on the trick, StealthCoder solves it in seconds, invisible to the proctor.
Companies that ask "Minimum Deletions to Make String Balanced"
Minimum Deletions to Make String Balanced 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 core challenge: you have a string of 'a' and 'b' characters, and you need the minimum deletions so that no 'a' comes after a 'b'. The trap is thinking you can greedily delete as you scan left to right. You can't. This requires dynamic programming or a stack-based insight. One approach: track the cost of keeping all 'a's before a point versus deleting them, then account for 'b's after that point. Another: use a stack to eliminate conflicting pairs and count what's left. Most candidates default to the brute force, which either times out or produces the wrong answer. The DP variant explicitly states: what's the minimum cost if we've decided to transition from 'a' phase to 'b' phase at each position. Common pitfall: not realizing you need to account for all 'a's that appear after your chosen transition point. This is where StealthCoder's real-time solution surfaces the working approach during your screen share, letting you move on without derailing.
Pattern tags
You know the problem.
Make sure you actually pass it.
Minimum Deletions to Make String Balanced 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. 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.
Minimum Deletions to Make String Balanced interview FAQ
Is this problem really just a greedy scan?+
No. Greedy fails because you can't decide locally whether to delete a character without knowing the full string structure ahead. This requires either dynamic programming to track the cost of different deletion strategies, or a stack to simulate the balancing process. Greedy will give you a wrong answer on most test cases.
What's the key insight that makes this DP-solvable?+
The insight is that a balanced string has all 'a's before all 'b's, or is empty. So you can iterate through the string and at each position, calculate the cost of everything up to that point if it were the transition boundary. Track minimum 'a's deleted so far and 'b's encountered, then combine them.
Can a stack approach work instead of DP?+
Yes. Push characters onto a stack, and whenever you see 'b' and the top is 'a', pop the 'a' instead of pushing. At the end, the stack contains only the characters that can't be balanced. The size of the stack is your answer. It's often faster to code during a live OA.
How often is this asked at other companies besides RedBus?+
It appears in moderate frequency across online assessments, especially at mid-tier tech companies and startups. The acceptance rate of 65 percent suggests it's not a ultra-rare problem, but it's not a classic either. You'll benefit from knowing the pattern.
What's the most common mistake candidates make?+
Assuming you can determine the answer by just counting 'a's and 'b's globally, or by deleting greedily from left to right. Both fail because the problem requires understanding the global structure. DP or stack forces you to think about state, which is why those approaches work.
Want the actual problem statement? View "Minimum Deletions to Make String Balanced" on LeetCode →