You are given an array of CPU `tasks`, each represented by letters A to Z, and a cooling interval `n`. Each cycle or interval allows the completion of one task. Tasks can be completed in any order, but there's a constraint: identical tasks must be separated by at least `n` intervals because of cooling time.
Return the minimum number of intervals the CPU will take to finish all the given tasks.
### Constraints
- `1 <= tasks.length <= 10^4`
- `tasks[i]` is an uppercase English letter.
- `0 <= n <= 100`
### Input Format
- Line 1: Space-separated uppercase characters representing the tasks.
- Line 2: An integer `n` representing the cooling interval.
### Output Format
Print the least number of intervals.
Sample Cases
Example 1Sample Case
Input: A A A B B B
2
Output: 8
Example 2Sample Case
Input: A A A B B B
0
Output: 6
Example 3Sample Case
Input: B B B A A A
2
Output: 8
Example 4Sample Case
Input: A
0
Output: 1
Constraints
Runtime Limit: 2000 ms per test batch
Memory Limit: 256 MB
Standard I/O stream reading
Official submissions are evaluated against hidden test cases on the server to verify time & memory complexity.