Class Solution
java.lang.Object
g1701_1800.s1793_maximum_score_of_a_good_subarray.Solution
1793 - Maximum Score of a Good Subarray.<p>Hard</p>
<p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<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>
<p>Return <em>the maximum possible <strong>score</strong> of a <strong>good</strong> subarray.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [1,4,3,7,4,5], k = 3</p>
<p><strong>Output:</strong> 15</p>
<p><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.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [5,5,4,5,4,1,1,1], k = 0</p>
<p><strong>Output:</strong> 20</p>
<p><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.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>1 <= nums[i] <= 2 * 10<sup>4</sup></code></li>
<li><code>0 <= k < nums.length</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maximumScore
public int maximumScore(int[] nums, int k)
-