Trains the technique from
LeetCode 1665Minimum Initial Energy to Finish TasksThis 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 field engineer runs a round of service calls on one battery pack. calls[i] = [drain_i, floor_i] describes call i:
drain_i is the charge the call burns, deducted once the call is finished;floor_i is the charge the pack must be showing at the moment the call is started, otherwise the diagnostic tool refuses to run it.Every call must be made exactly once, and the engineer may take them in any order. The pack is not recharged during the round. Note that a call's threshold is never below its drain, so finishing a call never leaves the pack below zero.
Return the smallest charge the pack can start the round with so that some order gets through all of the calls.
Example 1
A pack starting on 14 gets through the round in the order [4,9], [2,6], [7,8]: 14 clears the threshold 9 and drops to 10, 10 clears 6 and drops to 8, 8 clears 8 and drops to 1.
Example 2
Each call burns exactly what its threshold demands, so the pack carries the full 8 into the round: it clears the first threshold, drops to 3, clears the second and finishes on 0.
Example 3
One call cannot start below 10000, and a pack on 10000 runs it down to 9999, then the call needing 11 down to 9993, then the call needing 9 down to 9984.
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 smallest_starting_charge(calls: list[list[int]]) -> int:public int smallestStartingCharge(int[][] calls)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.