Coinbase: Minimum days to run tasks in a fixed order with a per-type cooldown
Problem. You get a sequence of tasks and a cooldown n. Two tasks of the same type must run at least n days apart, while different types have no restriction. You can run at most one task per day, and idle days are allowed. Unlike the well-known version, the order is fixed: tasks must run exactly in the given sequence. Return the total number of days needed.
Approach. Store the last day each type ran. For each task, if it is still cooling down, jump to the last run day plus n + 1. Otherwise move to the next day.
Follow-ups.
- What happens when
n = 0? - What does an empty task list return?
- What if task ids are arbitrary strings?
- Where would a future maintainer most likely introduce a bug? The candidate pointed to the
+1and pulled it into a named variable with a comment.
What the interviewer cared about. Maintainable, hard-to-break code more than speed. The candidate first confused this with the reorderable version and had to restart, so confirm early whether reordering is allowed.
Comments 0
No comments yet. Ask the author something, or add what happened in your own round.