Largest sum of k consecutive values
Coding problemEasyAsked in: NPCI, OYO
Given a list of integers nums and a whole number k, look at every run of exactly k consecutive values. Return the largest sum among those runs.
Values can be negative, so the answer can be negative too.
Examples
Example 1
Input: nums = [2,1,5,1,3,2], k = 3
Output: 9
The run 5, 1, 3 adds up to 9.
Example 2
Input: nums = [-1,-2,-3], k = 1
Output: -1
Example 3
Input: nums = [4,4], k = 2
Output: 8
Constraints
- 1 <= k <= n <= 200,000, where n is the number of values
- Each value is between -10,000 and 10,000
Run checks the 3 examples. Submit also runs the hidden tests: edge cases, large inputs and a time limit.
Run your code to see the results here. Ctrl or Cmd + Enter runs; add Shift to submit.
to answer and keep your progress. Reading is free for everyone.