Trains the technique from
LeetCode 1046Last Stone WeightThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A glassworks has a bench of molten gobs; gobs[i] is the weight of gob i in grams.
While at least two gobs are on the bench, the gaffer picks the two heaviest of them, say of weights x and y with x <= y, and presses them together:
x == y, both gobs are spent and nothing is left of either;y - x grams.When two gobs tie for heaviest, it does not matter which is picked. Return the weight of the gob left on the bench when no further press is possible, or 0 if the bench ends up empty.
Example 1
Pressing 7 with 3 leaves a 4 gram gob, so the bench holds [4, 2]. Pressing 4 with 2 leaves a 2 gram gob, and that is the last one.
Example 2
Pressing 10 with 4 gives [6, 3, 2]; pressing 6 with 3 gives [3, 2]; pressing 3 with 2 leaves a single gram.
Example 3
Each press is between equal weights, so the bench ends up empty.
Example 4
A single gob has no partner, so no press happens and it stays as it is.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def last_stone_weight(gobs: list[int]) -> int:public int lastStoneWeight(int[] gobs)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.