Implement the taskSchedulerIntervals method that returns the minimum intervals required to schedule tasks with cooldown.
The input contains a string tasks and an integer cooldown. Each character represents one task type.
The same task type must have at least cooldown intervals between two executions. Different task types can be executed without waiting.
Your task is to return the minimum number of intervals needed to complete all tasks. Idle intervals may be required if no valid task can be executed.
Use the frequency of the most common task to calculate the minimum schedule length.
The most frequent task creates gaps that must be filled by other tasks or idle intervals. If the maximum frequency is maxFreq, it creates maxFreq - 1 full blocks of size cooldown + 1. Add the number of tasks that share the maximum frequency for the last block.
The answer is the larger value between this calculated frame size and the total number of tasks.
Pseudocode:
function taskSchedulerIntervals(tasks, cooldown):
frequency = count each task character
maxFreq = largest frequency
maxCount = number of tasks with frequency maxFreq
frameSize = (maxFreq - 1) * (cooldown + 1) + maxCount
answer = maximum(length of tasks, frameSize)
return answer