# Design a task scheduler — coding interview question

Aced (formerly Exponent) publishes a public search API over its indexed pages; the guide is at https://www.aced.io/agents/agent-access.

Source: https://www.aced.io/questions/3504/design-task-scheduler
Source observed: 2026-11-05T00:08:15.659Z
Last checked: 2026-11-05T00:08:15.659+00:00
Indexed: 2026-11-06T19:29:26.331+00:00

---

# Design a task scheduler

We provide interview-practice questions, interview experiences, courses, and coding practice through Aced (formerly Exponent). This medium Data Structures & Algorithms / Coding question asks you to schedule repeated tasks with a cooldown interval.

## Question

You are given a list of tasks, with each task represented by a character. Execute every task in sequence while ensuring that the same task is not executed again until after a cooldown period of `n` intervals. Idle intervals are allowed when necessary. Write a function `leastInterval` that returns the minimum number of intervals needed to complete all tasks, including required idle time.

## Examples

### Cooldown `n = 2`

```text
tasks = ['A', 'A', 'A', 'B', 'B', 'B']
n = 2
output: 8
```

One valid minimum schedule is:

```text
['A', 'B', 'idle', 'A', 'B', 'idle', 'A', 'B']
```

The idle intervals ensure that repeated executions of the same task are separated by the required cooldown. The minimum is `8` intervals.

### Cooldown `n = 0`

```text
tasks = ['A', 'A', 'A', 'B', 'B', 'B']
n = 0
output: 6
```

With no cooldown, no idle time is needed, so the minimum equals the number of tasks: `6` intervals.

## Question metadata

- Difficulty: Medium
- Category: [Data Structures & Algorithms](https://www.aced.io/questions?type=algorithms)
- Also categorized as [Coding](https://www.aced.io/questions?type=coding)
- Roles associated with this question: [Software Engineer](https://www.aced.io/questions?role=swe), [Site Reliability Engineer](https://www.aced.io/questions?role=sre), [AI Engineer](https://www.aced.io/questions?role=ai-engineer), and [Machine Learning Engineer](https://www.aced.io/questions?role=ml-engineer)
- Companies associated with this question: [Google](https://www.aced.io/questions?company=google), [OpenAI](https://www.aced.io/questions?company=openai), and [Brex](https://www.aced.io/questions?company=brex)
- The question was reported as last asked 8 days ago at the observation captured on 2026-11-05.

The detailed company statistics and the question's solution are available through [Upgrade](https://www.aced.io/upgrade?src=questions). No community answers had been contributed in the supplied content. The practice interface includes Question, Solution, and Community tabs, an editor with Output and Test Results tabs, a Console, and a sign-up gate to run code: [Sign up to run code](https://www.aced.io/signup?src=lesson).

## Interview experiences

Three shared experiences accompany this question:

- **[Brex](https://www.aced.io/experiences/brex-software-engineer-interview-aed5a4) — Software Engineer — 8 days ago**

  > "The recruiter screen was pretty standard. The phone screen was ~3 parts, it was a \"practical coding\" question which was essentially 2 LC easy then a medium. Onsite was debugging (pretty straightforward, find 4 1-line bugs based on failing testcases), ai coding (vibe code a p2p app), and system design (design a p2p app)."

- **[Google](https://www.aced.io/experiences/google-site-reliability-engineer-interview-82ea20) — Site Reliability Engineer, Entry Level / L3 — 2 months ago**

  > "It was smooth I had a python coding interview and then Googlyness questions which were based on projects I have worked so far"

- **[OpenAI](https://www.aced.io/experiences/openai-software-engineer-interview-20a84c) — Software Engineer — 10 months ago**

  > "I got into the process through cold outreach plus a referral, and even that took a month or two of pushing before I got the first interview. After a pretty normal recruiter screen, I had two same-day phone rounds: one coding and one system design. The onsite was four rounds for me: coding, system design, technical deep dive on my own project, and behavioral. My big takeaway is that the coding bar is much more intense than standard big tech and feels closer to Anthropic, while the system design and behavioral pieces are more familiar. I was still waiting on the decision when we talked, and the biggest wildcard in the whole process was interviewer variability."

## Related questions

- [Implement a task scheduler.](https://www.aced.io/questions/7433/implement-task-scheduler-system)
- [Design a timer system.](https://www.aced.io/questions/949/design-timer-system)
- [Design a cache controller.](https://www.aced.io/questions/948/design-cache-controller)

## Related courses

### [AI Engineering Interview Prep](https://www.aced.io/courses/ai-engineering)

![AI Engineering Interview Prep](https://images.ctfassets.net/x78yjrjc11pq/25mhKSvDOiCwC89lDj89Ah/9a5fbfacc8d93f05c238ab55baa4e5e5/fde.png?w=800&h=800&fm=webp&q=75)

We help candidates prepare for AI engineering interviews at companies such as Google, Anthropic, Meta, and OpenAI with frameworks, example questions, and mock interviews with senior engineers. Topics include system design, AI/ML concepts, AI-assisted coding, and behavioral rounds.

### [Generative AI Interviews](https://www.aced.io/courses/gen-ai-interviews)

![Generative AI Interviews](https://images.ctfassets.net/x78yjrjc11pq/BLBU7an1PjT0Mt2ZzAfDa/60e119c8bff0cfb8281dcb497177f6e3/AdobeStock_1510292201-min.jpeg?w=800&h=800&fm=webp&q=75)

We help candidates prepare for interviews at AI-first and AI-powered companies. The course covers how generative AI works, where it fails, responsible use, AI products in production, LLMs, RAG systems, and real-world deployment.

## Aced interview-preparation areas

We offer courses and practice across Product Management, Forward Deployed Engineering, Engineering Management, Software Engineering, System Design, Data Science, Machine Learning, Data Engineering, AI Engineering, Investment Banking, Generative AI, Security Engineer, TPM, Solutions Architect, UX / Product Design, and BizOps & Strategy. We also provide interview experiences, questions, coding practice, coaching, resume review, salary negotiation, job referrals, and related resources.

---

[Read this page’s summary](https://www.aced.io/agents/api/public/v1/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3504%2Fdesign-task-scheduler&trace=t_679ff9ab98f3)

## Ask a follow-up about this page

Need a more specific answer? Ask the exact question you have. It returns a fresh, cited answer from Aced (formerly Exponent)’s knowledge base. No account or API key required.

Open this URL with your own question, URL-encoded. Include your question in q. All research inputs are optional; no account or setup.

`GET https://www.aced.io/agents/agent/faq?q={question}&trace=t_679ff9ab98f3`

[Tool guide and examples](https://www.aced.io/agents/agent-access) · [OpenAPI](https://www.aced.io/agents/api/public/v1/openapi.json) · [Page TLDR form](https://www.aced.io/agents/agent-tools/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3504%2Fdesign-task-scheduler). Opening a form does not execute a tool.