Sums of Every Window
A window is a block of exactly k consecutive items of nums. Return the sums of all the windows, from the window that starts at index 0 to the window that ends at the last item, in that order.
There are len(nums) - k + 1 windows when k fits. If k is larger than the number of items there is no window at all, so return an empty list.
Example 1
nums [1,2,3,4,5]
k 2
returns [3,5,7,9]
The windows are [1, 2], [2, 3], [3, 4] and [4, 5].
Example 2
nums [4,-1,2,1]
k 3
returns [5,2]
The windows are [4, -1, 2] and [-1, 2, 1].
Constraints
0 <= len(nums) <= 1001 <= k <= 100-1000 <= nums[i] <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.