Remove All Adjacent Duplicates In String

Asked atSwiggy
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
  1. 01Use output as a stack
  2. 02Read each character
  3. 03Pop equal top
  4. 04Otherwise push
  5. 05Return stack contents

Reference answer

Then expect these follow-ups

  • Why is one left-to-right pass sufficient?

    Tests: correctness reasoning

  • How does the k-duplicate variant change?

    Tests: constraint adaptation

Free to read · better with Enzo

Practice this out loud with Enzo

Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.

Next question