Tap here to switch tabs
Problem
Submissions

Problem: Maximum and Minimum Sums of at Most Size K Subarrays

Try to solve the Maximum and Minimum Sums of at Most Size K Subarrays problem.

Statement

You are given an integer array nums and an integer k.

Calculate the sum of the minimum and maximum values of all contiguous subarrays of nums that have a size of at most k.

Return the sum of the minimum and maximum elements across all such subarrays.

Constraints:

  • 1≤1 \leq nums.length ≤80000\leq 80000

  • 1≤1 \leq k ≤\leq nums.length

  • −106≤-10^6 \leq nums[i] ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum and Minimum Sums of at Most Size K Subarrays

Try to solve the Maximum and Minimum Sums of at Most Size K Subarrays problem.

Statement

You are given an integer array nums and an integer k.

Calculate the sum of the minimum and maximum values of all contiguous subarrays of nums that have a size of at most k.

Return the sum of the minimum and maximum elements across all such subarrays.

Constraints:

  • 1≤1 \leq nums.length ≤80000\leq 80000

  • 1≤1 \leq k ≤\leq nums.length

  • −106≤-10^6 \leq nums[i] ≤106\leq 10^6