Task Scheduler — C++ Coding Problem
Difficulty: medium | Category: greedy
Problem Description
Given a characters array `tasks` (CPU tasks, each labeled A–Z) and a non-negative integer `n` (the cooldown period between the same task), return the **minimum number of CPU intervals** required to finish all tasks. The CPU can idle if there's no valid task available. Input format: `task1 task2 ... taskN|n` **Constraints:** - `1 <= tasks.length <= 10⁴` - `tasks[i]` is uppercase English letter - `0 <= n <= 100` **Hint:** The task with maximum frequency determines the minimum intervals.
Examples
Example 1
Input: tasks = ["A","A","A","B","B","B"], n = 2
Output: 8
Explanation: A→B→idle→A→B→idle→A→B
Example 2
Input: tasks = ["A","A","A","B","B","B"], n = 0
Output: 6