Remove All Adjacent Duplicates in String

Problem Given a string, repeatedly remove any two adjacent equal characters. A removal can bring new neighbours together, so keep removing until no adjacent pair of equal characters remains. Return the final string.

Input / Output

  • Input: a string s.
  • Output: the string after all possible adjacent-duplicate removals.

Constraints

  • 1 <= |s| <= 10^5. Lowercase letters (clarify).
  • The result may be empty.

Example

  • "abbaca" -> "ca" (remove "bb" -> "aaca", then "aa" -> "ca").
  • "azxxzy" -> "ay".
added …
LeaderboardSalaryAccount