Stone Game IX

Alice and Bob continue their games with stones. There is a row of n stones, and each stone has an associated value. You are given an integer array stones, where stones[i] is the value of the i^th stone.

Alice and Bob take turns, with Alice starting first. On each turn, the player may remove any stone from stones. The player who removes a stone loses if the sum of the values of all removed stones is divisible by 3. Bob will win automatically if there are no remaining stones, even if it is Alice's turn.

Assuming both players play optimally, return true if Alice wins and false if Bob wins.

Example 1
Inputstones = [2,1]
Outputtrue
The sum of the removed stones is 1 + 2 = 3 and is divisible by 3, so Bob loses and Alice wins the game.
Example 2
Inputstones = [2]
Outputfalse
Alice removes the only stone, the sum is not divisible by 3, and since no stones remain, Bob wins the game.

Constraints

  • 1 <= stones.length <= 10^5
  • 1 <= stones[i] <= 10^4

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate