Skip to main content
PreparationZone Logo
PreparationZone
Back to Coding

Coding · Medium · Pro

Task scheduler with cooldown n between same tasks

CodingGreedyStaff
Model answerPreview

Approach

  • Count frequencies; most frequent task drives minimum length.
  • Formula: (maxFreq - 1) * (n + 1) + countOfMax, capped by tasks.length.

Java Solution

Java
public int leastInterval(char[] tasks, int n) {…