Roadmap › Stage 4: Stacks › Pattern 16 of 53
DSA pattern guide

Stack — Simulation

Characters cancel each other: backspaces, adjacent duplicates, reacting pairs.

Stage 4 · Stacks4 problems3 Easy · 1 Medium

Use it when

Characters cancel each other: backspaces, adjacent duplicates, reacting pairs.

Key idea

Walk the string and treat the stack as the result so far. Pop when the new character cancels the top.

Practice problems, in order

  1. Backspace String CompareEasy
  2. Remove All Adjacent DuplicatesEasy
  3. Make the String GreatEasy
  4. Minimum String Length After Removing SubstringsMedium

How to practise this pattern

  1. Read the problem and look for the signal above before writing any code.
  2. Say the brute force out loud, with its time complexity, then ask what work it repeats.
  3. Apply the key idea and write the optimised version yourself.
  4. If you're stuck for more than 10 minutes, take one small hint, not the full solution.
  5. Move to the next problem only when you can explain why this pattern fits.

Stuck on one of these?

The AlgoSolveo extension (free, launching soon) sits beside the LeetCode problem and gives the smallest hint that gets you moving, never the full answer. Solved problems tick off on your roadmap.

Join the extension waitlistTrack it on the roadmap
← Previous patternStack — ParenthesisNext pattern →Stack — Design