← Back to problems
Anduril • unique string drill
Replace All "aa"
AeroSpace • Anduril • cascading substring scrub
Remove every occurrence of "aa". Removals can create new pairs — continue until none remain. "baaabaaa" → "baba". Stack O(n) beats naive while "aa" in s: s.replace(...).
TimeO(n)
SpaceO(n)
i: —stack: ""pops: 0
Current char
Pair pop ("aa")
Stack kept
inputbaaabaaa
stack[ ]
Ready
Press Play. Scan left→right; if top is
a and current is a, pop (delete the pair).