Standard Bar Heaps · Medium Problems O(N) · O(1)
A broadcast tower must air a batch of announcements; airing the same announcement twice without n cooling slots in between would violate regulator spacing rules. Each airing takes one slot, and idle slots are permitted. The programming chief wants the minimum number of slots to clear the whole batch legally.
Input: A string tasks where each character is a task type, and an integer n, the cooldown gap between identical tasks.
Output: Return the minimum total number of slots (including idles) needed to run every task.
1 <= tasks.length <= 10^4tasks consists of uppercase English letters0 <= n <= 100Input: {"tasks":"AAABBB","n":2}
Output: 8
Two max-frequency tasks fill the cooldown frames: (3-1)*3 + 2 = 8 slots.
Input: {"tasks":"A","n":2}
Output: 1
A single task needs one slot and no cooldown follows.