Thanksgiving Sale: Use Coupon Code THANKS25 to Get Extra 25% Off.
00DAYS
:
00HOURS
:
00MINUTES
:
00SECONDS
Leetcode Problem 2029. Stone Game IX
2029. Stone Game IX
Leetcode Solutions
Counting Remainders of Stones Modulo
Initialize three counters for the remainders when stones are divided by 3 (remainder 0, 1, and 2).
Iterate through the stones array and increment the corresponding counter based on the stone's value modulo 3.
If there are no stones with a remainder of 1 or 2, Bob wins by default.
If the count of stones with a remainder of 0 is even, Alice can win if there is at least one stone with a remainder of 1 and one with a remainder of 2.
If the count of stones with a remainder of 0 is odd, Alice can win if the absolute difference between the counts of stones with remainders of 1 and 2 is greater than 2.