Skip to content
LC-2365 Medium LeetCode

2365. Task Scheduler II

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 54% Topics: Array, Hash Table, Simulation
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(n)

import collections


# hash table
class Solution(object):
    def taskSchedulerII(self, tasks, space):
        """
        :type tasks: List[int]
        :type space: int
        :rtype: int
        """
        lookup = collections.defaultdict(int)
        result = 0
        for t in tasks:
            result = max(lookup[t], result+1)
            lookup[t] = result+space+1
        return result

Solution from kamyu104/LeetCode-Solutions · MIT