🚀

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

  1. Initialize three counters for the remainders when stones are divided by 3 (remainder 0, 1, and 2).
  2. Iterate through the stones array and increment the corresponding counter based on the stone's value modulo 3.
  3. If there are no stones with a remainder of 1 or 2, Bob wins by default.
  4. 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.
  5. 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.
  6. Return the result based on these conditions.
UML Thumbnail

Simple Greedy Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...