LeetCode solutions

2483. Task Scheduler II

My accepted Python solution to LeetCode problem 2483, Task Scheduler II, running in 115ms.

  • Difficulty: Medium
  • Python
  • Runtime 115ms
  • Memory 36.5MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 115ms, memory 36.5MB, accepted 2026-01-02.

python
class Solution:
    def taskSchedulerII(self, tasks: List[int], space: int) -> int:
        last_day = {}  # task_type -> last day it was performed
        day = 0
        
        for task in tasks:
            day += 1
            if task in last_day:
                # Need to wait at least space days
                day = max(day, last_day[task] + space + 1)
            last_day[task] = day
        
        return day

Source