Practice Maximum and Minimum Sums of at Most Size K Subarrays
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Hard#3430
LeetCode ProblemMaximum and Minimum Sums of at Most Size K Subarrays
Problem Statement
You are given an integer array nums and a positive integer k. Return the sum of the maximum and minimum elements of all subarrays with at most k elements.
Source: Maximum and Minimum Sums of at Most Size K Subarrays on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [1,2,3], k = 2
Output
20
# Example 2
Input
nums = [1,-3,1], k = 2
Output
-6
Constraints
1 <= nums.length <= 80000
1 <= k <= nums.length
-10^6 <= nums[i] <= 10^6
Related LeetCode Problems
Practice more problems similar to Maximum and Minimum Sums of at Most Size K Subarrays.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.