Problem · Array
Maximum Sum of Heights
Learn this problemProblem statement
Given positive maximum heights maxHeights, choose a positive height for every index so that height[i] <= maxHeights[i]. The resulting array must be mountain-shaped: for some peak index, heights do not decrease before the peak and do not increase after it.
Return the maximum possible sum of the chosen heights.
Interview follow-up
The interviewer asked follow-up questions about the approach, complexity, and possible alternatives.
Function
maximumSumOfHeights(maxHeights: int[]) → longExamples
Example 1
maxHeights = [5,3,4,1,1]return = 13Choosing [5,3,3,1,1] forms a mountain with sum 13.
Example 2
maxHeights = [6,5,3,9,2,7]return = 22More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026