Tap here to switch tabs
Problem
Submissions

Problem: Remove Colored Pieces if Both Neighbors Share a Color

Try to solve the Remove Colored Pieces if Both Neighbors Share a Color problem.

Statement

There are pieces arranged in a row, represented by a string colors where each character is either 'A' or 'B'. Alice and Bob play a game taking alternate turns, with Alice moving first.

On a player’s turn:

  • Alice may remove a piece colored 'A' only if both of its adjacent neighbors are also colored 'A'. She is not allowed to remove pieces at the ends of the row.

  • Bob may remove a piece colored 'B' only if both of its adjacent neighbors are also colored 'B'. He is not allowed to remove pieces at the ends of the row.

When a piece is removed, the adjacent pieces shift together to close the gap.

If a player is unable to make a valid move on their turn, that player loses, and the other player wins.

Assuming both players play optimally, return true if Alice wins the game, or false if Bob wins.

Constraints:

  • 1≤1 \leq colors.length ≤105\leq 10^5

  • colors consists of only the letters 'A' and 'B'

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Remove Colored Pieces if Both Neighbors Share a Color

Try to solve the Remove Colored Pieces if Both Neighbors Share a Color problem.

Statement

There are pieces arranged in a row, represented by a string colors where each character is either 'A' or 'B'. Alice and Bob play a game taking alternate turns, with Alice moving first.

On a player’s turn:

  • Alice may remove a piece colored 'A' only if both of its adjacent neighbors are also colored 'A'. She is not allowed to remove pieces at the ends of the row.

  • Bob may remove a piece colored 'B' only if both of its adjacent neighbors are also colored 'B'. He is not allowed to remove pieces at the ends of the row.

When a piece is removed, the adjacent pieces shift together to close the gap.

If a player is unable to make a valid move on their turn, that player loses, and the other player wins.

Assuming both players play optimally, return true if Alice wins the game, or false if Bob wins.

Constraints:

  • 1≤1 \leq colors.length ≤105\leq 10^5

  • colors consists of only the letters 'A' and 'B'