Days needed to finish recurring tasks
I was asked this
No reports yet. Sign in to say where you were asked it.
You run n recurring tasks. Task i runs for the first time on day 1 and then again every intervals[i] days, so it runs on days 1, 1 + intervals[i], 1 + 2 * intervals[i], .... Any number of task runs can happen on the same day.
Given intervals and a target goal, return the smallest day d such that the total number of task runs on days 1 through d is at least goal.
def min_days(intervals: list[int], goal: int) -> int: ...
Constraints
1 <= len(intervals) <= 10^51 <= intervals[i] <= 10^51 <= goal <= 10^9
Example 1
intervals = [3, 5], goal = 5 -> 7
The 3-day task runs on days 1, 4, 7. The 5-day task runs on days 1, 6. By day 6 there are 4 runs; day 7 brings the total to 5.
Example 2
intervals = [2, 2, 2], goal = 7 -> 5
All three tasks run on days 1, 3, 5. That is 3 runs by day 1, 6 by day 3, and 9 by day 5, so day 5 is the first day with at least 7.
Reconstructed from the reported question; details may differ from what interviewers ask.
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.
