Remove Touching Twins
In a string text, two equal letters standing side by side are touching twins. Delete a pair of touching twins, and repeat, until no pair is left; deleting one pair can bring two other letters together and make a new pair. Return the text that is left.
The result is the same whichever pair you delete first. Upper and lower case are different letters.
Examples
text = "abbaca" → "ca"
text = "azxxzy" → "ay"
text = "abc" → "abc"
text = "aaaa" → ""In the first example, deleting bb leaves "aaca"; now the two as touch, and deleting them leaves "ca".
Constraints
- Between 0 and 20,000 letters.
- Aim for O(n): look at each letter a constant number of times.
Console
›Run to see what your code prints
Run checks the 4 visible cases here, in your browser. Submit runs all 8 on the judge, 4 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.