Easy · Arrays

Max subarray sum (size k)

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=3

Output: best 12

Example 2

[1,4,2,10,2,3,1,0,20] · k=4

Output: best 24

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Arrays problems