We’re preparing your current view and syncing the latest data.
You are given an integer array representing the heights of different mountains. In one second, you can decrease the height of any one mountain by 1. Your task is to determine the minimum number of seconds required to reduce the height of all mountains to zero, following any specific constraints implied by the problem.
An integer array heights, representing the heights of the mountains.
An integer representing the minimum number of seconds needed to make all mountain heights zero.
Example 1
Input
[3,4,5,3,4]
Output
9
Explanation
You can decrement heights in a way that multiple reductions overlap, minimizing the total time. For instance, reduce the tallest mountain first and then others accordingly.