Campaign/Level 5 of 12
mediumSliding window1 bug

Best Weekly Sales

The "best k-day streak" widget breaks for stores that lose money every day.

maxSum(arr, k) returns the largest sum of k consecutive elements, or null if the array is shorter than k.

Fix the code so every test passes. Keep the function name maxSum.

Test cases

  • maxSum([2,6,9,2,1,8,5,6,3], 3) → 19
  • maxSum([-3,-1,-2], 2) → -3
  • maxSum([4,2,1,6], 4) → 13
  • maxSum([1], 2) → null

Hints

each hint costs XP

Stuck? Hints go from a nudge to the exact fix.