Easy · Arrays
Max sum of subarray size K
Given an integer array nums and an integer k with 1 ≤ k ≤ nums.length, return the largest sum of any k consecutive elements.
Examples
Example 1
[2,1,5,1,3,2], k=3Output: max sum = 9
Example 2
[1,9,-1,-2,7,3,-1,2], k=4Output: max sum = 13
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.