dsa · easy

Max Sum of Subarray of Size K

Return the maximum sum of any contiguous subarray of length k.

Arguments

**Example:** [2,1,5,1,3,2], k=39 ([5,1,3]).

Example

`` Input: [2,1,5,1,3,2] 3 Output: 9 ``

Constraints

1 <= k <= nums.length <= 10^5 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[2,1,5,1,3,2]
3

Expected:
9

Example 2

Input:
[2,3,4,1,5]
2

Expected:
7

Open in the Dojo editor