Code Room
CodingMediumcod-g111
Subject HeapsLevel Mid–Senior~30 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

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.