Given an array of integers and two integers k and m, find the maximum sum of a subsequence of length k that can be obtained by removing at most m elements from the array and then selecting k elements from the remaining array
Explanation: The optimal subsequence is [7, 4, 1] with sum 12, achieved by removing the element 2 and keeping the rest in the subsequence of length 3
Explanation: The optimal subsequence is [9, 8, 6, 4] with sum 27, achieved by removing the element 5 from the array
Explanation: The optimal subsequence is [2, 3] with sum 5
Maximum in each window using deque
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak