Trains the technique from
LeetCode 2460Apply Operations to an ArrayThis 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 conveyor carries a row of trays. counts[i] is how many parts sit in tray i, and a tray holding 0 parts is empty.
A settling run walks the row once from left to right. For each index i from 0 up to counts.length - 2, in that order, it looks at trays i and i + 1 as they stand at that moment. If both hold the same number of parts and that number is not 0, the contents of tray i + 1 are tipped into tray i, so tray i then holds twice as many parts as before and tray i + 1 becomes empty. Otherwise both trays are left alone. Every index is visited exactly once.
When the walk is over, the trays that still hold parts are pushed to the front of the row in the order they already had, and the empty trays follow them.
Return the row of tray contents after the settling run and the push.
Example 1
At index `0` the two trays of `8` become a tray of `16` and an empty tray. At index `1` the trays hold `0` and `5`, which are different, so nothing happens. At index `2` the two trays of `5` become `10` and an empty tray. At index `3` the trays hold `0` and `5`. Pushing the loaded trays forward gives `16, 10, 5` followed by the two empties.
Example 2
Indices `0`, `2` and `4` each tip a pair of `6`s into a `12`, and at indices `1` and `3` the left tray is already empty. Three loaded trays are pushed to the front.
Example 3
No index has two equal non-empty trays side by side, so no tipping happens and only the push takes place.
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 settle_line(counts: list[int]) -> list[int]:public int[] settleLine(int[] counts)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.