Task Scheduler
Problem statement
AMZ Interval Collection (A group of problems focused on operations involving intervals :) -
- Task Scheduler (Full-Time)
- Merge Intervals (Intern, NG)
- Find Overlapping Times (Intern)
- Get Maximum Sum Find Overlapping Times (Full-Time)
- Optimal Interval Difference
You are given an array of CPU tasks, each labeled with a letter from A to Z, and a number n. Each CPU interval can be idle or allow the completion of one task. Tasks can be completed in any order, but there's a constraint: there has to be a gap of at least n intervals between two tasks with the same label.
Return the minimum number of CPU intervals required to complete all tasks.
Examples
Example 1
tasks = ["A","A","A","B","B","B"]n = 2return = 8A possible sequence is: A -> B -> idle -> A -> B -> idle -> A -> B.
After completing task A, you must wait two intervals before doing A again. The same applies to task B. In the 3rd interval, neither A nor B can be done, so you idle. By the 4th interval, you can do A again as 2 intervals have passed.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.