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
Coding & Algorithms
Software Engineer
Intuit
October 30, 2025
Software Engineer
Craft Demonstration
Coding & Algorithms
Medium

13

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
Greedy Algorithm
Priority Queue
Scheduling
Heap
Simulation
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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
  1. 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}.
  2. **Initialize the Max H...

Submit Your Answer
Markdown supported

Related Questions