Code Room
CodingMediumcod-g041
Subject GreedyLevel Mid–Senior~20 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

You are given a list of CPU tasks, each labeled by an uppercase letter, and a cooldown integer n. Each task takes one unit of time, and identical task labels must be separated by at least n units (the CPU may idle during the gap). Tasks may be run in any order. Return the minimum number of time units needed to finish all tasks. Here 0 <= n <= 100 and there is at least one task.

Implement
least_interval(tasks: list[str], n: int) → int
Examples
in[["A","A","A","B","B","B"],2]out8
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.