Welcome to another thrilling chapter in Alice and Bob's strategic stone games! In this game theory puzzle, Alice and Bob face off in a high-stakes battle where one wrong move means instant defeat.
Here's the setup: You have a row of n stones, each with a specific value. Alice goes first, and players alternate turns removing any stone from the collection. But here's the twist that makes this game so treacherous: if the sum of all stones you've removed becomes divisible by 3, you lose immediately!
There's another cruel rule: if Alice can't make a move (no stones left), Bob wins automatically - even if it would have been Alice's turn.
Both players are strategic masterminds who play optimally. Your mission: determine if Alice can secure victory despite these challenging conditions.
Input: An integer array stones where stones[i] represents the value of the i-th stone.
Output: Return true if Alice can win with perfect play, false if Bob will triumph.
Input & Output
Constraints
- 1 โค stones.length โค 105
- 1 โค stones[i] โค 104
- Important: Alice starts first and loses if sum becomes divisible by 3