Trains the technique from
LeetCode 1962Remove Stones to Minimize the TotalThis 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 scrap yard weighs the shredded metal sitting in each of its bins: bins[i] is the load of bin i in kilos. A booked slot on the yard's compactor gives the crew exactly passes passes, and every one of them has to be used.
A single pass is aimed at one bin of the crew's choosing. It takes away half of that bin's current load, rounded down, and leaves the rest in the bin. A bin holding one kilo therefore loses nothing when a pass is aimed at it, and the same bin may be chosen on as many passes as the crew likes.
Return the smallest total load, across all bins, that can be left in the yard once the booked passes have all been used.
Example 1
The loads can be walked down to 3 and 3 by aiming two passes at the first bin and one at the second, leaving 6 kilos in the yard.
Example 2
Two of the bins drop from 7 to 4 kilos and the third is untouched, so 15 kilos remain.
Example 3
One workable slot ends with loads 7, 4, 5 and 6, which add up to the figure returned.
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 least_scrap_left(bins: list[int], passes: int) -> int:public int leastScrapLeft(int[] bins, int passes)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.