You are given an array of CPU tasks, each represented by a character from 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 is a constraint: identical tasks must be separated by at least n intervals.
Return the minimum number of intervals the CPU will take to finish all the given tasks.
tasks = ["A","A","A","B","B","B"], n = 28tasks = ["A","C","A","B","D","B"], n = 16tasks = ["A","A","A","B","B","B"], n = 061 <= tasks.length <= 10^4tasks[i] is an uppercase English letter0 <= n <= 100Expected time complexity: O(n)Run your code to see results
Use Cmd+Enter to run