#3430
Maximum and Minimum Sums of at Most Size K Subarrays
hard · 25.2% accepted · 80 likes · top 4%
array · math · stack · monotonic stack
Description
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.
Solution