Improve this: remove adjacent pairs

A code exercise of about 15 minutes: read the statement, solve «Improve this: remove adjacent pairs» in the browser and get a review like in a real interview.

Code · 15 min
Loading…

Statement

This removeAdjacentPairs(s) works: it removes two equal letters next to each other over and over until no pair is left ("abbaca" → "aaca" → "ca") and returns what remains. But it searches from the start again after every removal and doesn't finish in time on long texts. Do it in one pass and explain why it was slow.