FastPrepTask Scheduler with Cooldown
Problems/Task Scheduler with Cooldown

Task Scheduler with Cooldown

Google logoGoogle● MediumINTERNONSITE INTERVIEW

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Google Summer 2027 internship report names a Task Scheduler variation but does not disclose its changed rules, input model, or output. This practice version uses a conventional single-processor, unit-task, uniform-cooldown baseline; the disclosed task family supports an approximate source match of 35%.

You are given an array tasks of task type IDs and an integer cooldown. Each task takes one time unit on a single processor.

You may run the tasks in any order. In each time unit, run one task or leave the processor idle. Two tasks with the same type ID must have at least cooldown intervening time units. Other task types and idle time both count toward that gap.

Return the minimum total time needed to finish every task. Do not include any idle time after the last task finishes.

Function

leastInterval(tasks: int[], cooldown: int) → int

Examples

Example 1

tasks = [1,1,1,2,2]cooldown = 2return = 7

One optimal schedule is 1, 2, idle, 1, 2, idle, 1. Type 1 runs at times 0, 3, 6, with two intervening time units between repeats. Its three occurrences require at least seven time units, and this schedule achieves that bound.

Example 2

tasks = [1,1,2,2,3,3]cooldown = 1return = 6

The schedule 1, 2, 3, 1, 2, 3 finishes all six tasks without idle time. Every repeated type has two intervening tasks, which satisfies a cooldown of one. Six time units are necessary because only one task can run at a time.

Example 3

tasks = [7,7,7,7]cooldown = 0return = 4

A cooldown of zero allows consecutive occurrences of the same type. Run all four tasks in four time units.

Constraints

  • 1 <= tasks.length <= 10^4.
  • 1 <= tasks[i] <= 26.
  • 0 <= cooldown <= 100.

More Google Onsite Interview questions

  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Nickname-Constrained GroupingZoox · ONSITE INTERVIEW
  • Partition Into K-Size Consecutive GroupsDream11 · ONSITE INTERVIEWDream11 interview questions
  • Minimum Baskets with Distinct Fruit TypesAmazon · ONSITE INTERVIEW
  • Task Scheduler with CooldownSambaNova Systems · PHONE SCREEN · ONSITE INTERVIEWSambaNova Systems interview questions
  • Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
  • Minimum Distinct Prefix CostChubb · OAChubb interview questions
  • Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
  • Task Scheduler with CooldownTeradata · PHONE SCREEN
  • Rearrange Songs by AuthorZomato / Eternal · OAZomato / Eternal interview questions
  • 🐘 Keep Them Apart 🦙QRT · OA

Interview reports that mention this question

  • Google Intern Team Matching: 14 Experiences (Part 4 of 8)

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int leastInterval(int[] tasks, int cooldown) {
        // Write your code here.
    }
}
Checking account…