Notice Period

Best Sales Stretch

easy

A food truck logs its daily revenue. The owner wants to brag about her best k-day run — the k consecutive days with the highest combined revenue.

Given the list revenue and an integer k, return the maximum sum of any k consecutive entries. You may assume k <= len(revenue).

Example 1
in revenue = [4, 2, 1, 7, 8, 1, 2, 8, 1, 0], k = 3
out 16
Days [7, 8, 1] sum to 16, the best 3-day stretch.
Example 2
in revenue = [5, -3, 7], k = 2
out 4
[-3, 7] beats [5, -3].
Constraints
  • · 1 <= k <= len(revenue) <= 2000
  • · -10^4 <= revenue[i] <= 10^4
similar problem on LeetCode ↗
solution.pyloading python…
test results
Hit ▶ Run to test your code against the visible cases.