Leetcode 2365

Y Tech
Aug 7, 2023

Coding question asked in Meta interviews.

'''
When we are processing a task, we need to know the last day that we handled this task. We can use a dictionary to store this information.

tasks = [1,2,1,2,3,1], space = 3
day: 9
task: 1
memo = { // key is task, value is day
1: 9
2: 6
3: 7
}
'''
class Solution:
def taskSchedulerII(self, tasks: List[int], space: int) -> int:
day = 1
memo = dict()
for task in tasks:
if task in memo:
lastDay = memo[task]
day = max(day, lastDay + space + 1)
memo[task] = day
day += 1

return day - 1

--

--