Maximum Sum of k in a Row
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Write maxWindowSum(nums, k): return the largest sum of k numbers next to each other in nums. Numbers may be negative, and k is a whole number from 1 to nums.length, so nums is never empty. For example, maxWindowSum([2, -1, 3, 4, -6, 5], 3) is 6, from -1, 3 and 4. The checks include 100,000 numbers with k = 50,000, so adding up every window from scratch is too slow.
Your code must pass
- Finds the largest sum of k numbers in a row
- Handles negative numbers
- Works when k is 1 or the whole array
- Is fast enough for 100,000 numbers