Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task. There is a cooldown period n between two same tasks. Return the least number of units of time to finish all tasks.
- An array of characters
tasks. - An integer
n.
Input: tasks = ["A","A","A","B","B","B"], n = 2
Output: 8