One worker must finish a list of jobs. The array tasks holds the jobs, and each letter is a type of job. One job takes 1 minute. In each minute the worker does one job or waits (idle). The jobs can be done in any order.
There is a cool-down rule. After a job of some type, the next job of the same type must wait at least n minutes. In those n minutes the worker can do other jobs or stay idle.
Return the smallest number of minutes needed to finish all the jobs.
Examples
Example 1:
Input: tasks = ["A","A","B"], n = 2
Output: 4
Explanation: A -> B -> idle -> A. The two A jobs have 2 minutes between them.
Example 2:
Input: tasks = ["P","Q","R"], n = 5
Output: 3
Explanation: All jobs are of different types, so there is nothing to wait for.
Example 3:
Input: tasks = ["X","X","X","Y","Y","Z"], n = 2
Output: 7
Explanation: X -> Y -> Z -> X -> Y -> idle -> X.