Skip to content

Commit

Permalink
Merge pull request neetcode-gh#2994 from coopers/0621
Browse files Browse the repository at this point in the history
Update 0621-task-scheduler.py
  • Loading branch information
sujal-goswami authored Sep 11, 2023
2 parents c6f7c66 + dbdc945 commit 2ae20b0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions python/0621-task-scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ def leastInterval(self, tasks: List[str], n: int) -> int:
if q and q[0][1] == time:
heapq.heappush(maxHeap, q.popleft()[0])
return time


# Greedy algorithm
class Solution(object):
def leastInterval(self, tasks: List[str], n: int) -> int:
counter = collections.Counter(tasks)
max_count = max(counter.values())
min_time = (max_count - 1) * (n + 1) + \
sum(map(lambda count: count == max_count, counter.values()))

return max(min_time, len(tasks))

0 comments on commit 2ae20b0

Please sign in to comment.