Implement a Task Scheduler
Last updated: October 30, 2025
Quick Overview
Implement a task scheduler that executes tasks with cooldown constraints. Given tasks and a cooldown period n, find the minimum time to complete all tasks where the same task must wait at least n intervals before executing again.
Intuit
October 30, 202513
4
2,127 solved
Implement a task scheduler that executes tasks with cooldown constraints. Given tasks and a cooldown period n, find the minimum time to complete all tasks where the same task must wait at least n intervals before executing again.
Appears in Craft Demo variations and phone screens. Relevant to Intuit's background job processing where tasks like tax calculations have rate constraints.
What the Interviewer Expects
- Solve optimally using a greedy approach with a max heap
- Handle edge cases like all identical tasks and zero cooldown
- Write clean code that clearly expresses the scheduling logic
- Explain the greedy correctness argument
- Discuss real-world scheduling scenarios this models
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you modify this for tasks with different priorities?
- What if tasks have dependencies in addition to cooldown constraints?
- How would you implement this for a distributed task queue?
- Can you solve this without simulation using a mathematical approach?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Problem Analysis
This problem can be approached using a greedy algorithm combined with a max heap (priority queue). The key insight is that we need to execute the most frequent tasks first to minimize the overall time...
Approach
- Count Task Frequencies: Use a dictionary to count the occurrences of each task. For example, for tasks ['A', 'A', 'A', 'B', 'B'], the counts would be {'A': 3, 'B': 2}.
- **Initialize the Max H...