### Problem
Every tasks entry is a unit-time task labeled A through Z. Execute them in any order, inserting idle intervals if needed. Equal labels must have at least n intervening intervals. Return the minimum total intervals needed to finish all tasks.
```cpp
class Solution {
public:
int leastInterval(vector<char>& tasks, int n);
};
```
### Examples
**Example 1:**
```text
tasks = ["A","A","B"], n = 2
Output: 4
Explanation: A, B, idle, A is optimal.
```
**Example 2:**
```text
tasks = ["C","C","D","D"], n = 1
Output: 4
Explanation: C, D, C, D uses no idle interval.
```
### Constraints
- Task count: 1..10000. Every label is an English uppercase letter. Cooldown n: 0..100.
### Clarifying Questions
Count intervening intervals correctly and distinguish forced idle time from work that can fill cooldown gaps.
```hint Read the boundary condition
What lower bound is forced by the most frequent label and ties at that frequency?
```
### Contract considerations
Count intervening intervals correctly and distinguish forced idle time from work that can fill cooldown gaps.
Overview: Minimize CPU Intervals with Equal-Label Cooldowns. Every tasks entry is a unit-time task labeled A through Z.
Every tasks entry is a unit-time task labeled A through Z. Execute them in any order, inserting idle intervals if needed. Equal labels must have at least n intervening intervals. Return the minimum total intervals needed to finish all tasks.
class Solution {
public:
int leastInterval(vector<char>& tasks, int n);
};
Examples
Example 1:
tasks = ["A","A","B"], n = 2
Output: 4
Explanation: A, B, idle, A is optimal.
Example 2:
tasks = ["C","C","D","D"], n = 1
Output: 4
Explanation: C, D, C, D uses no idle interval.
Constraints
Task count: 1..10000. Every label is an English uppercase letter. Cooldown n: 0..100.
Clarifying Questions Guidance
Count intervening intervals correctly and distinguish forced idle time from work that can fill cooldown gaps.
Contract considerations
Count intervening intervals correctly and distinguish forced idle time from work that can fill cooldown gaps.