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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 115ms, memory 36.5MB, accepted 2026-01-02.
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