Search⌘ K
AI Features

Solution: Task Scheduler

Explore how to determine the minimum CPU intervals needed to complete all tasks given a cooling period. Learn to track task frequencies, optimize scheduling by prioritizing the most frequent tasks, and fill idle slots with less frequent ones. This lesson helps you implement a strategy to balance task execution and idle times effectively.

Statement

You are given an array of CPU tasks represented by uppercase letters (A to Z) and an integer n, which denotes the cooling period required between any two identical tasks. Each task takes exactly one CPU interval to execute. Therefore, each CPU interval can either perform a task or remain idle. Tasks can be executed in any order, but the same task must be separated by at least n intervals.

Determine the minimum number of CPU intervals required to complete all tasks.

Constraints:

  • 1 1 \leq ...