|
| 1 | +<p>You are given an integer array <code>nums</code>. In one operation, you can select a <span data-keyword="subarray-nonempty">subarray</span> and replace it with a single element equal to its <strong>maximum</strong> value.</p> |
| 2 | + |
| 3 | +<p>Return the <strong>maximum possible size</strong> of the array after performing zero or more operations such that the resulting array is <strong>non-decreasing</strong>.</p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong class="example">Example 1:</strong></p> |
| 7 | + |
| 8 | +<div class="example-block"> |
| 9 | +<p><strong>Input:</strong> <span class="example-io">nums = [4,2,5,3,5]</span></p> |
| 10 | + |
| 11 | +<p><strong>Output:</strong> <span class="example-io">3</span></p> |
| 12 | + |
| 13 | +<p><strong>Explanation:</strong></p> |
| 14 | + |
| 15 | +<p>One way to achieve the maximum size is:</p> |
| 16 | + |
| 17 | +<ol> |
| 18 | + <li>Replace subarray <code>nums[1..2] = [2, 5]</code> with <code>5</code> → <code>[4, 5, 3, 5]</code>.</li> |
| 19 | + <li>Replace subarray <code>nums[2..3] = [3, 5]</code> with <code>5</code> → <code>[4, 5, 5]</code>.</li> |
| 20 | +</ol> |
| 21 | + |
| 22 | +<p>The final array <code>[4, 5, 5]</code> is non-decreasing with size <font face="monospace">3.</font></p> |
| 23 | +</div> |
| 24 | + |
| 25 | +<p><strong class="example">Example 2:</strong></p> |
| 26 | + |
| 27 | +<div class="example-block"> |
| 28 | +<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3]</span></p> |
| 29 | + |
| 30 | +<p><strong>Output:</strong> <span class="example-io">3</span></p> |
| 31 | + |
| 32 | +<p><strong>Explanation:</strong></p> |
| 33 | + |
| 34 | +<p>No operation is needed as the array <code>[1,2,3]</code> is already non-decreasing.</p> |
| 35 | +</div> |
| 36 | + |
| 37 | +<p> </p> |
| 38 | +<p><strong>Constraints:</strong></p> |
| 39 | + |
| 40 | +<ul> |
| 41 | + <li><code>1 <= nums.length <= 2 * 10<sup>5</sup></code></li> |
| 42 | + <li><code>1 <= nums[i] <= 2 * 10<sup>5</sup></code></li> |
| 43 | +</ul> |
0 commit comments