Ctrl K

Halve the Total Load

Medium
Servers carry loads loads (positive numbers). One operation picks any server and cuts its load exactly in half; the result may be fractional, and the same server can be picked again later. Return the fewest operations after which the total load has dropped by at least half of its starting value.
Example 1
loads=[6, 2, 2] → 3

The total is 10, so at least 5 must go. 6 → 3 (3 removed), 3 → 1.5 (1.5 more), 2 → 1 (1 more): 5.5 in total.

Example 2
loads=[12] → 1

A single halving removes exactly half.

Example 3
loads=[4, 4] → 2

Halve each 4: 2 + 2 = 4 is removed, exactly half of 8.

Constraints
  • 1 ≤ len(loads) ≤ 10⁵
  • 1 ≤ loads[i] ≤ 10⁷
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsStudios for Recording Sessions MediumJobs With a Cooldown MediumSorted Into Runs of Three MediumSpread Out the Labels MediumSplicing Ropes Medium
loading Python…
Input
loads=[6, 2, 2]
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 77 tests on the server, hidden ones included.