i-th one weighs weights[i].
On each cycle the crusher picks the two **heaviest** boulders and smashes them together. Say their weights are a ≤ b:
- if a == b, both boulders turn to dust;
- otherwise the lighter one turns to dust and the heavier one now weighs b - a.
Cycles repeat while more than one boulder is left in the hopper. Return the weight of the remaining boulder, or 0 if none is left.weights=[6, 3, 9, 2] → 2
9 and 6 leave 3, so the pile is [3, 3, 2]; the two 3s destroy each other, leaving [2].
weights=[5, 5] → 0
Two equal boulders destroy each other, nothing is left, so the answer is 0.
weights=[14] → 14
weights=[6, 3, 9, 2]
2
Run checks the first 3 tests in your browser. Submit checks all 108 tests on the server, hidden ones included.