weights. In one move you pick any two stones with weights x ≤ y and smash them together:
- if x == y, both disappear;
- otherwise stone x disappears and stone y now weighs y - x.
Moves continue while more than one stone is left. Return the smallest possible weight of the stone that remains, or 0 if none is left.weights=[6, 4, 3, 2, 8] → 1
The total 23 is odd, so zero is impossible. Groups {6, 4, 2} and {3, 8} weigh 12 and 11, so a remainder of 1 is reachable, e.g. 8 - 6 = 2, 4 - 3 = 1, 2 - 2 = 0, and a stone of 1 is left.
weights=[5, 5] → 0
Two equal stones destroy each other, leaving 0.
weights=[40, 9, 7] → 24
weights=[6, 4, 3, 2, 8]
1
Run checks the first 3 tests in your browser. Submit checks all 89 tests on the server, hidden ones included.