You are given a 0-indexed array
maxHeights
ofn
integers.You are tasked with building
n
towers in the coordinate line. Theith
tower is built at coordinatei
and has a height ofheights[i]
.A configuration of towers is beautiful if the following conditions hold:
1 <= heights[i] <= maxHeights[i]
heights
is a mountain array.Array
heights
is a mountain if there exists an indexi
such 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 { |