Skip to content

Best k-day streak

EasySliding Window
Decode it first. Clues, constraints, pattern and plan before any code.

Given a list of daily sales nums and a window size k, return the largest sum of any k consecutive days.

nums = [2, 1, 5, 1, 3, 2], k = 3  →  9   (5 + 1 + 3)
nums = [-3, -1, -2],       k = 1  →  -1

Constraints

  • 1 <= k <= nums.length <= 10^5
  • -10^4 <= nums[i] <= 10^4