Skip to content

Practice Task Scheduler II

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2365
LeetCode Problem

Task Scheduler II

Problem Statement

Complete tasks in their given order, where tasks[i] is a task type. Each day either complete the next task or take a break. After completing a type, at least space intervening days must pass before performing that type again. Return the minimum number of days to complete all tasks.

Source: Task Scheduler II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
tasks = [1,2,1,2,3,1], space = 3
Output
9

# Example 2

Input
tasks = [5,8,8,5], space = 2
Output
6

Constraints

1 <= tasks.length <= 10^5
1 <= tasks[i] <= 10^9
1 <= space <= tasks.length

Related LeetCode Problems

Practice more problems similar to Task Scheduler II.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.