|
| 1 | +<h2><a href="https://leetcode.com/problems/maximum-score-of-a-good-subarray">1918. Maximum Score of a Good Subarray</a></h2><h3>Hard</h3><hr><p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p> |
| 2 | + |
| 3 | +<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <code>i <= k <= j</code>.</p> |
| 4 | + |
| 5 | +<p>Return <em>the maximum possible <strong>score</strong> of a <strong>good</strong> subarray.</em></p> |
| 6 | + |
| 7 | +<p> </p> |
| 8 | +<p><strong class="example">Example 1:</strong></p> |
| 9 | + |
| 10 | +<pre> |
| 11 | +<strong>Input:</strong> nums = [1,4,3,7,4,5], k = 3 |
| 12 | +<strong>Output:</strong> 15 |
| 13 | +<strong>Explanation:</strong> The optimal subarray is (1, 5) with a score of min(4,3,7,4,5) * (5-1+1) = 3 * 5 = 15. |
| 14 | +</pre> |
| 15 | + |
| 16 | +<p><strong class="example">Example 2:</strong></p> |
| 17 | + |
| 18 | +<pre> |
| 19 | +<strong>Input:</strong> nums = [5,5,4,5,4,1,1,1], k = 0 |
| 20 | +<strong>Output:</strong> 20 |
| 21 | +<strong>Explanation:</strong> The optimal subarray is (0, 4) with a score of min(5,5,4,5,4) * (4-0+1) = 4 * 5 = 20. |
| 22 | +</pre> |
| 23 | + |
| 24 | +<p> </p> |
| 25 | +<p><strong>Constraints:</strong></p> |
| 26 | + |
| 27 | +<ul> |
| 28 | + <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> |
| 29 | + <li><code>1 <= nums[i] <= 2 * 10<sup>4</sup></code></li> |
| 30 | + <li><code>0 <= k < nums.length</code></li> |
| 31 | +</ul> |
0 commit comments