Trains the technique from
LeetCode 2208Minimum Operations to Halve Array SumThis 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 rig carries loads given as nums. One easing picks any load and replaces it with exactly half of it, which may leave a fraction.
Return the fewest easings that bring the total of the loads down to at most half of what it started at.
Example 1
The loads total 70, so 35 has to come off. Easing 33 sheds 16.5, easing the 19 sheds 9.5, easing the 16.5 sheds 8.25, and that already covers 34.25; one more easing carries it past 35.
Example 2
The total is 4 and 2 has to come off. One easing sheds only 1, so a second is needed, and reaching exactly half is enough.
Example 3
A single easing halves the only load, which is exactly half the total.
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 halve_array(nums: list[int]) -> int:public int halveArray(int[] nums)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.