Loading...
Loading...
Loading...
A word is cleaned by removing two equal letters that stand next to each other. After a removal, new neighbours may become equal, and they are removed too. Repeat until no such pair is left. Print the cleaned word, or EMPTY if nothing is left.
Example 1
Input
abbaca
Output
ca
bb goes first, then aa. ca is left.
Example 2
Input
azxxzy
Output
ay
Try the problem first. Open one hint at a time.
Keep a stack of letters kept so far.
If the new letter equals the top, pop it. Otherwise push it.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor