Problem statement
You are given an array and a number k. Look at every group of k neighbouring values, add each group up, and return the largest total.
When the array is shorter than k there is no group, and the answer is 0 to mean none. Every value can be negative, so the largest total is not automatically the first group.
Examples
Inputnums = [2, 1, 5, 1, 3, 2], k = 3
Output9
The best group is 5 + 1 + 3 at positions 2 to 4.
Inputnums = [1, 2], k = 3
Output0
Two values cannot hold a group of three, so no group is scored.
The walkthrough is part of Premium
The statement and the examples above stay free. The full how-to-solve walkthrough, the cost notes in plain words and the interactive step-by-step visualizer unlock with a Premium plan.
See pricing