Remove All Adjacent Duplicates in String II
A medium-tier problem at 60% community acceptance, tagged with String, Stack. Reported in interviews at Attentive and 7 others.
Remove All Adjacent Duplicates in String II shows up in live assessments at Meta, Disney, Goldman Sachs, and Oracle. You're given a string and a count k; you need to delete every substring of k consecutive identical characters. It's a medium problem with a 59% acceptance rate, which means nearly half the candidates who see it blank or timeout. The trap is trying to brute-force with repeated passes over the string. If you haven't practiced the stack pattern and hit this live, StealthCoder surfaces the working solution invisible to the proctor.
Companies that ask "Remove All Adjacent Duplicates in String II"
Remove All Adjacent Duplicates in String II 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 a senior engineer who knows the OA is theater. This is the script.
Get StealthCoderThe trick is a stack with character-count pairs, not individual characters. Push each character onto the stack and track its consecutive count. When the count reaches k, pop k characters. This avoids repeated scans and handles cascading deletions correctly in a single pass. Most candidates either iterate the string multiple times (timeout), or treat the stack as a simple character list and lose track of counts. The stack approach is linear time and actually elegant once you see it. String and Stack are the topics, and the pattern applies to harder variants of duplicate removal too. On your live OA, if you can't nail the stack logic, StealthCoder generates a correct implementation in seconds.
Pattern tags
You know the problem.
Make sure you actually pass it.
Remove All Adjacent Duplicates in String II 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 a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Remove All Adjacent Duplicates in String II interview FAQ
Is this still asked at major companies.+
Yes. Meta, Disney, Goldman Sachs, and Oracle all report asking it. It appears in phone screens and online assessments. The 59% acceptance rate suggests it's neither a gimme nor a killer, but companies use it to filter candidates who can't spot the stack pattern.
What's the actual trick.+
Stack each character with a count of how many identical characters precede it. When the count hits k, pop k characters. This solves it in one pass. Most fail because they iterate multiple times or use a simple character stack without tracking counts.
How do I know when to use a stack for String problems.+
Stacks shine when you need to remove or match adjacent elements and changes can cascade. If deleting one pair triggers a new pair to form, stack is your friend. String problems on Stack topics usually hide this dependency.
Does this relate to other duplicate removal problems.+
Yes. Remove Duplicates in an Array, simplify path problems, and parenthesis matching all use the same stack logic. Once you own this pattern, you'll spot it in harder variants at the same companies.
What happens if I try a greedy or regex approach.+
Greedy fails because you can't always delete left to right. Regex is overkill and won't compile in most assessment environments. The stack approach is the intended solution at every company that asks this.
Want the actual problem statement? View "Remove All Adjacent Duplicates in String II" on LeetCode →