Understand the problem
Restate the problem precisely. Interviewers reward candidates who pause, define the contract, and name the guarantees before coding.
Given a characters array `tasks`, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one unit of time. For each unit of time, the CPU could complete either one task or just be idle. However, there is a non-negative integer `n` that represents the cooldown period between two **same tasks** (the same letter in the array). That is, there must be at least `n` units of time between any two same tasks. Return the *least number of units of time* that the CPU will take to finish all the given tasks.
Once you've drafted a response, click Submit for AI review and a senior engineer will critique your reasoning.