165. Remove Adjacent Duplicates
Core1000 ms256 MBSolved by 0%
Repeatedly remove any two adjacent equal characters until none remain, and print what is left.
In abbaca the bb goes first, leaving aaca; then the aa goes, leaving ca.
Print Empty if the whole string disappears.
Constraints - The line has between 1 and 100000 characters. - Lowercase letters only.
Input
A single line of lowercase letters.
Output
Print what remains after all removals, or Empty if the whole string disappears.
Inputabbaca
Outputca
Noterequires a removal to expose a second one
Inputabcd
Outputabcd
Notehas no adjacent duplicates at all
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.