Skip to content

Practice Maximum Score of a Good Subarray

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1793
LeetCode Problem

Maximum Score of a Good Subarray

Problem Statement

You are given an array of integers nums (0-indexed) and an integer k. The score of a subarray (i, j) is defined as min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1). A good subarray is a subarray where i <= k <= j. Return the maximum possible score of a good subarray.

Source: Maximum Score of a Good Subarray on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,4,3,7,4,5], k = 3
Output
15

# Example 2

Input
nums = [5,5,4,5,4,1,1,1], k = 0
Output
20

Constraints

1 <= nums.length <= 10^5
1 <= nums[i] <= 2 * 10^4
0 <= k < nums.length

Related LeetCode Problems

Practice more problems similar to Maximum Score of a Good Subarray.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.