|
6 | 6 |
|
7 | 7 | ## Description
|
8 | 8 |
|
9 |
| -<p>You are given a <strong>0-indexed</strong> array <code>maxHeights</code> of <code>n</code> integers.</p> |
| 9 | +<p>You are given an array <code>heights</code> of <code>n</code> integers representing the number of bricks in <code>n</code> consecutive towers. Your task is to remove some bricks to form a <strong>mountain-shaped</strong> tower arrangement. In this arrangement, the tower heights are non-decreasing, reaching a maximum peak value with one or multiple consecutive towers and then non-increasing.</p> |
10 | 10 |
|
11 |
| -<p>You are tasked with building <code>n</code> towers in the coordinate line. The <code>i<sup>th</sup></code> tower is built at coordinate <code>i</code> and has a height of <code>heights[i]</code>.</p> |
| 11 | +<p>Return the <strong>maximum possible sum</strong> of heights of a mountain-shaped tower arrangement.</p> |
12 | 12 |
|
13 |
| -<p>A configuration of towers is <strong>beautiful</strong> if the following conditions hold:</p> |
| 13 | +<p> </p> |
| 14 | +<p><strong class="example">Example 1:</strong></p> |
14 | 15 |
|
15 |
| -<ol> |
16 |
| - <li><code>1 <= heights[i] <= maxHeights[i]</code></li> |
17 |
| - <li><code>heights</code> is a <strong>mountain</strong> array.</li> |
18 |
| -</ol> |
| 16 | +<div class="example-block"> |
| 17 | +<p><strong>Input:</strong> <span class="example-io">heights = [5,3,4,1,1]</span></p> |
19 | 18 |
|
20 |
| -<p>Array <code>heights</code> is a <strong>mountain</strong> if there exists an index <code>i</code> such that:</p> |
| 19 | +<p><strong>Output:</strong> <span class="example-io">13</span></p> |
21 | 20 |
|
22 |
| -<ul> |
23 |
| - <li>For all <code>0 < j <= i</code>, <code>heights[j - 1] <= heights[j]</code></li> |
24 |
| - <li>For all <code>i <= k < n - 1</code>, <code>heights[k + 1] <= heights[k]</code></li> |
25 |
| -</ul> |
| 21 | +<p><strong>Explanation:</strong></p> |
26 | 22 |
|
27 |
| -<p>Return <em>the <strong>maximum possible sum of heights</strong> of a beautiful configuration of towers</em>.</p> |
| 23 | +<p>We remove some bricks to make <code>heights = [5,3,3,1,1]</code>, the peak is at index 0.</p> |
| 24 | +</div> |
28 | 25 |
|
29 |
| -<p> </p> |
30 |
| -<p><strong class="example">Example 1:</strong></p> |
| 26 | +<p><strong class="example">Example 2:</strong></p> |
31 | 27 |
|
32 |
| -<pre> |
33 |
| -<strong>Input:</strong> maxHeights = [5,3,4,1,1] |
34 |
| -<strong>Output:</strong> 13 |
35 |
| -<strong>Explanation:</strong> One beautiful configuration with a maximum sum is heights = [5,3,3,1,1]. This configuration is beautiful since: |
36 |
| -- 1 <= heights[i] <= maxHeights[i] |
37 |
| -- heights is a mountain of peak i = 0. |
38 |
| -It can be shown that there exists no other beautiful configuration with a sum of heights greater than 13.</pre> |
| 28 | +<div class="example-block"> |
| 29 | +<p><strong>Input:</strong> <span class="example-io">heights = [6,5,3,9,2,7]</span></p> |
39 | 30 |
|
40 |
| -<p><strong class="example">Example 2:</strong></p> |
| 31 | +<p><strong>Output:</strong> <span class="example-io">22</span></p> |
| 32 | + |
| 33 | +<p><strong>Explanation:</strong></p> |
41 | 34 |
|
42 |
| -<pre> |
43 |
| -<strong>Input:</strong> maxHeights = [6,5,3,9,2,7] |
44 |
| -<strong>Output:</strong> 22 |
45 |
| -<strong>Explanation:</strong> One beautiful configuration with a maximum sum is heights = [3,3,3,9,2,2]. This configuration is beautiful since: |
46 |
| -- 1 <= heights[i] <= maxHeights[i] |
47 |
| -- heights is a mountain of peak i = 3. |
48 |
| -It can be shown that there exists no other beautiful configuration with a sum of heights greater than 22.</pre> |
| 35 | +<p>We remove some bricks to make <code>heights = [3,3,3,9,2,2]</code>, the peak is at index 3.</p> |
| 36 | +</div> |
49 | 37 |
|
50 | 38 | <p><strong class="example">Example 3:</strong></p>
|
51 | 39 |
|
52 |
| -<pre> |
53 |
| -<strong>Input:</strong> maxHeights = [3,2,5,5,2,3] |
54 |
| -<strong>Output:</strong> 18 |
55 |
| -<strong>Explanation:</strong> One beautiful configuration with a maximum sum is heights = [2,2,5,5,2,2]. This configuration is beautiful since: |
56 |
| -- 1 <= heights[i] <= maxHeights[i] |
57 |
| -- heights is a mountain of peak i = 2. |
58 |
| -Note that, for this configuration, i = 3 can also be considered a peak. |
59 |
| -It can be shown that there exists no other beautiful configuration with a sum of heights greater than 18. |
60 |
| -</pre> |
| 40 | +<div class="example-block"> |
| 41 | +<p><strong>Input:</strong> <span class="example-io">heights = [3,2,5,5,2,3]</span></p> |
| 42 | + |
| 43 | +<p><strong>Output:</strong> <span class="example-io">18</span></p> |
| 44 | + |
| 45 | +<p><strong>Explanation:</strong></p> |
| 46 | + |
| 47 | +<p>We remove some bricks to make <code>heights = [2,2,5,5,2,2]</code>, the peak is at index 2 or 3.</p> |
| 48 | +</div> |
61 | 49 |
|
62 | 50 | <p> </p>
|
63 | 51 | <p><strong>Constraints:</strong></p>
|
64 | 52 |
|
65 | 53 | <ul>
|
66 |
| - <li><code>1 <= n == maxHeights <= 10<sup>3</sup></code></li> |
67 |
| - <li><code>1 <= maxHeights[i] <= 10<sup>9</sup></code></li> |
| 54 | + <li><code>1 <= n == heights <= 10<sup>3</sup></code></li> |
| 55 | + <li><code>1 <= heights[i] <= 10<sup>9</sup></code></li> |
68 | 56 | </ul>
|
69 | 57 |
|
70 | 58 | ## Solutions
|
|
0 commit comments