Best k-day run in a cyclic sprint schedule
I was asked this
No reports yet. Sign in to say where you were asked it.
A training program is made of n back-to-back sprints. Sprint i lasts days[i] days. On day j of a sprint (counting from 1 within that sprint), finishing that day's work earns j points. So a 4-day sprint is worth 1, 2, 3, 4 on its four days.
The program is cyclic: when the last sprint ends, sprint 0 starts again, and this repeats forever.
You will train for exactly k consecutive days. You may start on any day of any sprint, and the run may wrap from the last sprint into the next loop. Return the maximum total points you can earn.
Implement:
def max_sprint_points(days: list[int], k: int) -> int: ...
Constraints
1 <= n <= 10^51 <= days[i] <= 10^91 <= k < sum(days)- Sprint lengths can be large, so a solution that walks day by day is too slow.
Example 1
days = [3, 1, 4], k = 5. One loop earns 1 2 3 | 1 | 1 2 3 4. The best run of 5 days takes the last two days of sprint 2 (3, 4) and then all of sprint 0 in the next loop (1, 2, 3), for 13.
Example 2
days = [2, 5], k = 3. The best run is the last three days of the 5-day sprint, 3 + 4 + 5 = 12.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
Sign in to submit your code; every attempt is kept here.
