Cancel Adjacent Equal Pairs
Remove equal neighbors, including pairs created by earlier removals, with one stack pass.
The problem
Implement reduce_adjacent_pairs(tokens). Whenever two equal tokens sit next to each other, remove both. Removing a pair can bring two new equal tokens together, and those are removed too. Keep going until no two neighbors are equal, and return the tokens that remain, in their original order. For example, ["a", "b", "b", "a", "c"] gives ["c"]: removing the two "b" tokens brings the two "a" tokens together, and they cancel as well. tokens may be empty.
Starter code
def reduce_adjacent_pairs(tokens):
passPublic examples
tokens = ["a", "b", "b", "a", "c"]gives["c"]tokens = [1, 2, 3]gives[1, 2, 3]
Solving it in the practice book needs an active paid plan.
Open it in the practice bookOne thought at a time.
