Improve this: the best k-day streak

A code exercise of about 10 minutes: read the statement, solve «Improve this: the best k-day streak» in the browser and get a review like in a real interview.

Code · 10 min
Loading…

Statement

This maxWindowSum(nums, k) works: it returns the largest sum of k numbers in a row (1 ≤ k ≤ the list's length). But it recomputes every run from scratch and, with many years of sales and a big k, it doesn't finish in time. Make it fast and explain why it was slow.