Busiest Stretch
A site logs its visits per day in the list visits. Given a number of days k, find the k consecutive days with the most visits in total, and return that total.
Examples
visits = [3, 1, 4, 1, 5, 9, 2, 6], k = 3 → 17
visits = [5], k = 1 → 5
visits = [0, 0, 7, 0], k = 2 → 7In the first example the last three days, 9 + 2 + 6, add up to 17.
Constraints
- Between 1 and 100,000 days, each with between 0 and 1,000 visits.
kis at least 1 and at most the number of days.- Aim for O(n): adding up every window from scratch costs n × k.
Console
›Run to see what your code prints
Run checks the 3 visible cases here, in your browser. Submit runs all 6 on the judge, 3 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.