Last stone left after smashing
You have a pile of stones whose weights, positive integers, are in stones. Each turn, take the two heaviest stones, weighing x ≤ y, and smash them together: if x == y both are destroyed, otherwise the lighter one is destroyed and the other now weighs y - x. Repeat while at least two stones remain. Return the weight of the stone left at the end, or 0 if none is left.
Aim for O(n log n): don't re-sort the pile on every turn.
Besides the tests, one large input (20,000 stones) with a ~450 ms limit (scaled to your device's speed): brute force won't pass.
Examples
last_stone([2,7,4,1,8,1])→1last_stone([3,3])→0last_stone([10,4])→6