Return the largest sum of k consecutive values in nums.
For nums = [2, 1, 5, 1, 3, 2] and k = 3 the answer is 9 (5 + 1 + 3).
The starter code adds up every window from scratch. It is correct but too slow when k is large.
Example 1
Input:
max_sum_k([2, 1, 5, 1, 3, 2], 3)
Output:
9
Example 2
Input:
max_sum_k([2, 3, 4, 1, 5], 2)
Output:
7
1 <= k <= len(nums) <= 200000-10**4 <= nums[i] <= 10**4No results yet
Run your code to check it against the examples, or submit to run every test.