leetcode 621 task scheduler python

from collections import Counter

class Solution(object):
    def leastInterval(self, tasks, n):
        """
        :type tasks: List[str]
        :type n: int
        :rtype: int
        """
        # init = tasks.popleft()
        cnt = Counter("".join(tasks))
        (init, _) = cnt.most_common(1)[0]
        cnt.subtract({init: 1})
        # init = tasks.pop(0)
        schedule = [init]
        interval = {init: 0}
        i = 1
        idx = 0
        recompute = True
        while True:
            if recompute:
                tasks_sorted = [t for (t, k) in cnt.most_common() if k != 0]
                n_tasks = len(tasks_sorted)
            if n_tasks == 0:
                break
            noop = 0
            success = False
            for t in tasks_sorted:
                if t not in schedule or i-interval[t] > n:
                    schedule.append(t)
                    interval[t] = i
                    cnt.subtract({t: 1})
                    i += 1
                    success = True
                    recompute = True
                    break
            if not success:
                recompute = False
                schedule.append('idle')
                i += 1
        # print schedule
        return len(schedule)

Hot pastes

hello, world
     2321 | Never
free anonymous http proxies
     1043 | 2022-07-12
Office 2021 activation.bat
     893 | 2022-12-12
leetcode 621 task scheduler python
     269 | Never
log4j search
     185 | Never
AVAST Software License File
     116 | Never
asfasfasfasfas
     102 | 2023-03-05
sggag
     76 | 2023-06-12
safsafasfsaf
     31 | 2023-06-22
زيوت عطرية
     23 | 2023-03-17