Back to Month
MEDIUM 16 Aug 2026 View on LeetCode

2029. Stone Game IX

</> Solution

class Solution {
    public boolean stoneGameIX(int[] stones) {
        int[] cnt = new int[3];
        for (int s : stones) {
            cnt[s % 3]++;
        }

        if (cnt[0] % 2 == 0) {
            return cnt[1] >= 1 && cnt[2] >= 1;
        } else {
            return Math.abs(cnt[1] - cnt[2]) > 2;
        }
    }
}

TIME COMPLEXITY

O(n)

SPACE COMPLEXITY

O(1)

TOPICS

Array Counting Game Theory Greedy Math