Minimum String Length After Removing Substrings
A easy-tier problem at 77% community acceptance, tagged with String, Stack, Simulation. Reported in interviews at Yelp and 1 others.
You're given a string and told to repeatedly remove "AB" or "CD" substrings until you can't anymore, then return what's left. Sounds simple. Yelp and J.P. Morgan ask this one. The acceptance rate is 77%, which means most people get it, but the trick is spotting that a greedy simulation fails on certain inputs. You need to think about order of operations. If you blank on the approach during your OA, StealthCoder surfaces the working solution invisible to the proctor.
Companies that ask "Minimum String Length After Removing Substrings"
Minimum String Length After Removing 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. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop.
Get StealthCoderThe naive approach is to loop through the string, find and remove "AB" or "CD", then restart. That works but it's inefficient and easy to get wrong on edge cases. The real pattern: use a Stack. Process characters one by one. When you see a character, check if it pairs with the top of the stack to form "AB" or "CD". If it does, pop the stack instead of pushing. If not, push the character. This single pass guarantees all possible removals happen because you catch pairs as you build the result. The string and stack topics are core here, and the simulation of the process is where bugs hide. Most candidates either implement the inefficient loop or mishandle the stack logic. StealthCoder is your hedge if the stack pattern doesn't click in the live moment.
Pattern tags
You know the problem.
Make sure you actually pass it.
Minimum String Length After Removing 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. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimum String Length After Removing Substrings interview FAQ
Is this really asked at Yelp and J.P. Morgan, or is it just easy prep?+
Both companies have confirmed reports of asking it. At 77% acceptance, it's labeled easy. But easy doesn't mean it always clicks in real time. The stack trick isn't obvious if you default to string search and loop. It's the kind of problem you either see the pattern on or you spend 10 minutes debugging a slow solution.
What's the trick I'm missing if my loop-based solution times out?+
You're likely restarting your search after every removal, which is O(n squared) or worse. The stack approach is O(n) single pass. Build a stack as you iterate. Check the top of the stack against the current character for "AB" or "CD" pairs. Pop if matched, push otherwise. One loop, one result.
Does this problem actually test stack knowledge or is it simulation disguised as stack?+
Both. The string and stack topics overlap here. You're simulating the removal process, but the stack is the data structure that makes simulation efficient and correct. Without the stack abstraction, you end up rewriting string operations and losing the elegance. The real learning is seeing how stack elegantly models the problem.
What happens if I have nested removals like 'ABCD'?+
Stack handles it. Process 'A', push. Process 'B', it matches 'A' on stack, pop. Process 'C', push. Process 'D', it matches 'C' on stack, pop. Result is empty. If you're doing string search and replace, you might miss the cascade. Stack catches it in one pass.
Is this problem still being asked or is it old news?+
Recent reports from Yelp and J.P. Morgan confirm it's still in rotation. 77% acceptance suggests it's a screening problem, not a hard filter. It weeds out candidates who can't spot the stack pattern, but it's not designed to break strong engineers. Expect it if you're interviewing there.
Want the actual problem statement? View "Minimum String Length After Removing Substrings" on LeetCode →