Task Scheduler

Problem Id: 621 Difficulty: Medium


Intuition

Solution


class Solution:
    def leastInterval(self, tasks: List[str], n: int) -> int:
        counts = collections.Counter(tasks).values()
        m = max(counts)
        mct = list(counts).count(m)
        return max(len(tasks), mct + (n + 1) * (m - 1))