stacks[i] is the height of stack i (0 means it is empty). In one round a worker picks an integer x > 0 no greater than the height of the lowest **non-empty** stack and removes exactly x crates from every non-empty stack.
Return the fewest rounds needed to empty all the stacks.stacks=[4, 0, 2, 4, 6] → 3
Take 2 from each: [2, 0, 0, 2, 4]. Take 2 again: [0, 0, 0, 0, 2]. Then the last 2: all empty after three rounds.
stacks=[0, 0] → 0
All stacks are already empty.
stacks=[3, 3, 3] → 1
stacks=[4, 0, 2, 4, 6]
3
Run checks the first 3 tests in your browser. Submit checks all 115 tests on the server, hidden ones included.