You are given a list of CPU tasks represented by uppercase letters. Each task takes exactly one interval, and the same letter must be separated by at least n idle or different-task intervals before it can run again. Return the minimum number of intervals needed to finish all tasks.
Input / output
tasks: string[], n: intExamples
tasks = ["A","A","A","B","B","B"], n = 2 returns 8 because one optimal schedule is A, B, idle, A, B, idle, A, B.tasks = ["A","C","A","B","D","B"], n = 1 returns 6 because no idle time is needed.tasks = ["A","A","A","B","B","B"], n = 0 returns 6.Constraints
1 <= tasks.length <= 10^4tasks[i] is a single uppercase English letter0 <= n <= 100Target complexity
O(tasks.length) time and O(1) extra space beyond the fixed-size frequency table.Hints
Follow-up How would you build an explicit schedule string if an interviewer asked you to print one valid timeline instead of only the minimum length?