You are given a 0-indexed array
maxHeightsofnintegers.You are tasked with building
ntowers in the coordinate line. Theithtower is built at coordinateiand has a height ofheights[i].A configuration of towers is beautiful if the following conditions hold:
1 <= heights[i] <= maxHeights[i]heightsis a mountain array.Array
heightsis a mountain if there exists an indexisuch that:
- For all
0 < j <= i,heights[j - 1] <= heights[j]- For all
i <= k < n - 1,heights[k + 1] <= heights[k]Return the maximum possible sum of heights of a beautiful configuration of towers.
1 | class Solution { |