1047. Remove All Adjacent Duplicates In String

Practice Remove All Adjacent Duplicates In String for free on NudgeCode: Easy, Stack pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

s consists of lowercase letters. Repeatedly pick two equal letters that sit next to each other and delete both of them, until no such pair is left. Return the final string; it is the same no matter which pairs you delete first.

Each step removes exactly one pair, not a whole run: "aaa" becomes "a".

Example

s = "abbaca"  ->  "ca"   (delete "bb" -> "aaca", then "aa" -> "ca")
s = "aaa"     ->  "a"

Constraints