#1793
Maximum Score of a Good Subarray
expert · 1090 · lc hard +32 · verified · 64.4% accepted · 2,002 likes · top 68%
Description
You are given an integer array nums and an integer k. The score of subarray (i, j) is min(nums[i..j]) * (j - i + 1). A good subarray has i <= k <= j. Return the maximum score of any good subarray.
Example 1:
Input: nums = [1,4,3,7,4,5], k = 3
Output: 15
Explanation: The optimal subarray is (1, 5) with a score of min(4,3,7,4,5) * (5-1+1) = 3 * 5 = 15.
Example 2:
Input: nums = [5,5,4,5,4,1,1,1], k = 0
Output: 20
Explanation: The optimal subarray is (0, 4) with a score of min(5,5,4,5,4) * (4-0+1) = 4 * 5 = 20.
Code
1
2
3