111. Best Window of Size K
Core1000 ms256 MBSolved by 0%
Print the largest sum of any k consecutive elements in the array.
Constraints - `1 ≤ k ≤ n ≤ 200000` - `-1000000 ≤ a[i] ≤ 1000000`
Input
The first line contains two integers n and k.
The second line contains n space-separated integers.
Output
Print one integer, the largest sum of any k consecutive elements.
Input5 2
1 4 10 2 3
Output14
Notehas its best window in the middle
Input5 5
1 2 3 4 5
Output15
Notehas a window covering the whole array
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.