Easy · Arrays
Maximum Subarray Sum of Size K (Sliding window)
Given an integer array values and an integer k with 1 ≤ k ≤ values.length, return the maximum sum of any k consecutive elements.
Examples
Example 1
[2,1,5,1,3,2,7,1] · k=3Output: best 12
Example 2
[1,4,2,10,2,3,1,0,20] · k=4Output: best 24
Rebuild it in the studio
Core interview problems are free with a full runner and lessons; Pro opens the complete library.