Minimum Number of Seconds to Make Mountain Height Zero - Problem
You are given an integer mountainHeight denoting the height of a mountain. You are also given an integer array workerTimes representing the work time of workers in seconds.
The workers work simultaneously to reduce the height of the mountain. For worker i:
- To decrease the mountain's height by
x, it takesworkerTimes[i] + workerTimes[i] * 2 + ... + workerTimes[i] * xseconds.
For example:
- To reduce the height of the mountain by
1, it takesworkerTimes[i]seconds. - To reduce the height of the mountain by
2, it takesworkerTimes[i] + workerTimes[i] * 2seconds, and so on.
Return an integer representing the minimum number of seconds required for the workers to make the height of the mountain 0.
Input & Output
Example 1 — Basic Case
$
Input:
mountainHeight = 4, workerTimes = [2,1,1]
›
Output:
3
💡 Note:
Worker 1 reduces 1 unit (time: 2), Worker 2 reduces 2 units (time: 1+2=3), Worker 3 reduces 1 unit (time: 1). Maximum time is 3.
Example 2 — Single Worker
$
Input:
mountainHeight = 3, workerTimes = [3]
›
Output:
18
💡 Note:
Only worker reduces all 3 units: 3×1 + 3×2 + 3×3 = 3 + 6 + 9 = 18 seconds.
Example 3 — Equal Workers
$
Input:
mountainHeight = 5, workerTimes = [1,1]
›
Output:
6
💡 Note:
Optimal distribution: Worker 1 gets 3 units (1+2+3=6), Worker 2 gets 2 units (1+2=3). Maximum time is 6.
Constraints
- 1 ≤ mountainHeight ≤ 105
- 1 ≤ workerTimes.length ≤ 104
- 1 ≤ workerTimes[i] ≤ 106
Visualization
Tap to expand
Understanding the Visualization
1
Input
Mountain height=4, workers=[2,1,1] with increasing work per unit
2
Process
Distribute work optimally among workers working simultaneously
3
Output
Minimum time=3 when work is distributed efficiently
Key Takeaway
🎯 Key Insight: Binary search on the total time needed, then verify if workers can collectively finish within that time using optimal work distribution
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code