Leetcode - Task Scheduler (Python)

preview_player
Показать описание
July 2020 Leetcode Challenge
Leetcode - Task Scheduler
Рекомендации по теме
Комментарии
Автор

man tim, you are so good at explaining. I've watched other youtubers do this problem, this is probably the best one.very helpful!

janmichaelaustria
Автор

It took me around 5 rewatches before it finally clicked but now it makes sense (I think... still a bit confused on what i is, I think its accounting for idle cycles)

oooo-rcyf
Автор

Finally got an intuitive solution to this problem! Thank you!

PoojaM-je
Автор

Thanks for sharing this approach!
I think in the internal while loop you can probably add another condition after line 17 that checks if not h and just adds the remaining idle times to output so that you don't have to run the while loop with just output += 1 happening. Correct me if I'm wrong.

Ramakrishnan-bqis
Автор

thank youu for this solution! most direct and clear one for that problem

sam_sleem
Автор

A similar but easy approach which I found from the discuss section and also faster than 96%:
if not tasks:
return 0

count_dict = Counter(tasks)
lst = sorted(count_dict.values(), reverse=True)
#print(lst)
most_common = lst[0]
counter = 0
i=0
while i<len(lst) and lst[i]==most_common:
counter += 1
i += 1

ret = (most_common - 1) * (n+1) + counter
#print(ret)
return max(len(tasks), ret)

siddharthsingh
Автор

Thank you Tim! It is really readable, understandable and very helpful!

linglin
Автор

How does your code handle cool down when it’s a single task A which needs to execute 4 times with n =4.

mym
Автор

Really easy and good solution Tim! Can you please also share the time complexity?

lalitgoski
Автор

Thank you for the awesome explanation. I'd like to ask why does it have to be heapq.heappush(h, (-v, k)) at first and then later when appending from temp, heapq.heappush(h, (k, v)) instead?

yoonalim