In Stone Game IX, Alice and Bob play a game with an array of stones. Alice goes first. On each turn, a player removes a stone and adds its value to a running sum. The player loses if the current sum becomes divisible by 3 after their turn, or if they are forced to take a stone when no stones are left (in which case Bob wins if any stones were originally there, under specific rules). The stones' actual values don't matter as much as their values modulo 3.
This problem is a favorite at Samsung and Google because it tests your ability to simplify complex game rules using mathematical observations. It requires you to categorize items (counting stones with remainder 0, 1, or 2) and analyze the game's flow based on these counts. It's a great test of Math, Counting, and Game Theory interview pattern knowledge.
The primary pattern is Counting and Game Theory. You count how many stones have remainders 0, 1, and 2 when divided by 3. Stones with remainder 0 are "neutral"—they don't change the sum's divisibility by 3, but they can be used to pass the turn back and forth. The game's outcome mostly depends on the relative counts of remainder-1 and remainder-2 stones and whether the number of remainder-0 stones is even or odd.
Suppose you have:
if-else branches instead of finding the underlying parity rules.When a problem involves divisibility, always think about the remainder (modulo). Categorizing the input into remainders often reveals a pattern that makes the full simulation unnecessary.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Maximum Median Sum of Subsequences of Size 3 | Medium | Solve | |
| Maximum Number of Coins You Can Get | Medium | Solve | |
| Minimum Operations to Make Array Equal II | Medium | Solve | |
| Stone Game VI | Medium | Solve | |
| Minimum Replacements to Sort the Array | Hard | Solve |