FastPrepAdjacent Equal-Pair Removal Game

Adjacent Equal-Pair Removal Game

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA
Learn

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) → String

Examples

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 <= 100000
  • values contains lowercase English letters.

More ZipRecruiter problems

See ZipRecruiter hiring insights
public String pairRemovalWinner(String values) {
    // Write your code here.
}
values"aa"
expected"Alice"
Checking account…