Objective
A fixed-size sliding window of size k moves along the list: when it advances one element enters and another leaves, so the sum is updated in O(1) instead of being recomputed.
Instructions
- The first line has space-separated integers and the second an integer
k(always between 1 and the amount of numbers). - Show
Maximum sum: xwith the largest sum ofkconsecutive elements.
1 4 2 10 2 3 1 0 20
4
Maximum sum: 24
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise