Adjacent Equal-Pair Removal Game
Problem statement
Alice and Bob play a game on a string values. Alice moves first. On each move, remove any adjacent equal pair; the remaining characters close together.
A player who cannot move loses. Return "Alice" or "Bob" assuming optimal play.
Function
pairRemovalWinner(values: String) → StringExamples
Example 1
values = "aa"return = "Alice"Alice removes the only pair, leaving Bob without a move.
Example 2
values = "abba"return = "Bob"Two cancellations occur, so Bob makes the final move.
Constraints
0 <= values.length <= 100000valuescontains lowercase English letters.