Remove Adjacent Duplicate Pairs
Problem statement
Given a string text, repeatedly remove any pair of equal adjacent characters until no such pair remains.
Removing one pair may make a new equal pair adjacent. Return the final string after all possible removals. The final result is unique regardless of the order in which valid pairs are removed.
Function
removeAdjacentDuplicatePairs(text: String) → StringExamples
Example 1
text = "abbaca"return = "ca"Remove bb to get aaca, then remove aa to get ca.
Example 2
text = "azxxzy"return = "ay"Removing xx exposes zz; removing that pair leaves ay.
Example 3
text = "abc"return = "abc"No adjacent characters are equal, so the string is unchanged.
Constraints
0 <= text.length <= 100000textcontains only lowercase English letters.