Trains the technique from
LeetCode 3296Minimum Number of Seconds to Make Mountain Height ZeroThis 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 spoil heap holds mountainHeight units. Digger i works at a rate given by workerTimes[i]: clearing x units takes that digger workerTimes[i] * x * (x + 1) / 2 seconds in total.
Every digger works at the same time as the others, and between them they must clear the whole heap. Return the fewest seconds until the heap is gone, which is the longest any one digger has to work.
Example 1
Splitting the ten units five apiece has each digger spend 2 times 15, which is 30 seconds, and no other split of the heap finishes sooner.
Example 2
The single digger must clear all ten units, which costs 4 times 55.
Example 3
The slow digger is worth one unit at most: taking one costs it a million seconds, while the fast digger clearing all three costs only six. Leaving it idle is better, so the answer is the fast digger's six seconds.
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 min_number_of_seconds(mountainHeight: int, workerTimes: list[int]) -> int:public long minNumberOfSeconds(int mountainHeight, int[] workerTimes)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.