Minimum Days for Fixed-Order Tasks with Cooldown
Updated
Problem statement
You are given an array tasks of string task IDs and a nonnegative integer cooldown. Execute every task exactly once, in the supplied order, with at most one task executed per day.
If the same task ID was last executed on day d, its next execution must be no earlier than day d + cooldown + 1. You may insert idle days, but you may not reorder tasks.
Return the minimum total number of days needed to execute the complete sequence. Return 0 when tasks is empty.
Function
minimumDays(tasks: String[], cooldown: int) → longExamples
Example 1
tasks = ["A","B","A"]cooldown = 2return = 4Execute A on day 1 and B on day 2. Day 3 must be idle, so the second A runs on day 4.
Example 2
tasks = ["x","x","x"]cooldown = 0return = 3With a zero-day cooldown, equal tasks may run on consecutive days.
Example 3
tasks = []cooldown = 5return = 0No execution days are needed for an empty sequence.
Constraints
0 <= tasks.length <= 100000.- Each task ID is a non-empty string containing at most 50 Unicode characters.
0 <= cooldown <= 1000000000.- Tasks must be executed in their given order.
- The answer fits in a signed 64-bit integer.
More Coinbase interview questions
- Scheduled Payments with Account AliasesONSITE INTERVIEW · Seen Oct 2026
- Dynamic Fixed-K Score LeaderboardONSITE INTERVIEW · Seen Aug 2026
- Sliding-Window Averages as Reduced FractionsONSITE INTERVIEW · Seen Aug 2026
- Parse and Order Structured LogsONSITE INTERVIEW · Seen Aug 2026
- Select Transactions with Child-Pays-for-Parent PackagesPHONE SCREEN · Seen Oct 2026
- Task Management SystemOA · Seen Sep 2026
- Cloud Compute Credits SystemOA · Seen Aug 2026
- Banking System with Historical SnapshotsOA · Seen Aug 2026
- Find the Length of the Longest Common PrefixOA · Seen Oct 2024
- Lexicographically Smallest Topological OrderPHONE SCREEN · Seen Apr 2022
Similar questions at other companies
- Sustained Overspeed AlertsFleetx · ONSITE INTERVIEW
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Deep Copy a Random-Pointer ListAmazon · ONSITE INTERVIEW
- Instant-Runoff Voting WinnerWise · ONSITE INTERVIEW
- Escape Room LeaderboardPinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
- Random Picks Excluding Recent ValuesGoogle · ONSITE INTERVIEWGoogle interview questions
- Most Frequent Call Path in Interleaved LogsRoblox · ONSITE INTERVIEWRoblox interview questions
- Read a File from Distributed ChunksHudson River Trading · ONSITE INTERVIEWHudson River Trading interview questions