FastPrepMaximum Sum of Heights
Problems/Maximum Sum of Heights

Maximum Sum of Heights

Amazon logoAmazon● HardONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem is backed by a real Amazon onsite interview report. The report identified Maximum Sum of Heights as choosing one peak to maximize the mountain-array sum, but it did not restate the per-index cap rule, function interface, examples, or constraints. The core task match is about 85%.

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: List<Integer>) → long

Examples

Example 1

maxHeights = [5,3,4,1,1]return = 13

Choosing [5,3,3,1,1] forms a mountain with sum 13.

Example 2

maxHeights = [6,5,3,9,2,7]return = 22

Constraints

  • 1 <= maxHeights.length <= 10^5
  • 1 <= maxHeights[i] <= 10^9

More Amazon problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
class Solution {
    public long maximumSumOfHeights(List<Integer> maxHeights) {
      // write your code here
    }
}
Checking account…