Task scheduling with cooldown

Write codeMedium30 minMeta style

Your task

Given a list of tasks represented by uppercase letters and a non-negative integer n, where each task takes one unit of time, find the least time needed to finish all tasks. The same task must be separated by at least n units of idle (or other) time between two executions. Return the total number of time units (including any idle slots) required. The task list has 1 to 10^4 tasks and n is between 0 and 100.

Examples

least_interval(tasks: list[str], n: int) -> int
Example 1
Inputleast_interval(["A", "A", "A", "B", "B", "B"], 2)
Output8