A word game removes any two equal letters that sit next to each other. Removing a pair can bring two other equal letters together, and they are removed too, until no two neighbors are equal. For example abbaca becomes aaca and then ca.
Write cancelPairs(text) that returns the final string. The result is the same whatever order the pairs are removed in.
Input: text = "abbaca" Output: "ca"
bb goes, which makes aa neighbors, so they go too.
Input: text = "azxxzy" Output: "ay"
xx, then zz are removed.
0 <= text.length <= 10^5text has lowercase letters.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #251 Cancel Matching Neighbors. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.