LC 1046 — Problem

You have an array of positive integers stones, each representing a stone's weight. Each round, pick the two heaviest stones. If they're equal, both shatter. Otherwise, the lighter one shatters and the heavier one becomes a new stone weighing the difference. Return the weight of the last remaining stone, or 0 if all shatter.

Input: stones = 274181
Output: 1

Constraints: 1 ≤ stones.length ≤ 30 · 1 ≤ stones[i] ≤ 1000.

Phase 1: Tap to smash the two heaviest stones

Four Stones in a Row

Four stones: 5372. Each round, the two heaviest collide. The lighter one shatters. The heavier one chips — the chip that survives equals the DIFFERENCE. Last stone standing wins.

FIG. 1 — STARTING ROW (SORTED)

Before any smashing: will the final stone weigh zero, non-zero, or can you tell yet?