[
greedy
queue
heap
array
]
BinarySearch 0329 Task Schedule
Problem statement
https://binarysearch.com/problems/Task-Schedule/
Solution
Equal to Leetcode 0621. Task Scheduler.
Complexity
It is O(n)
for time and space.
Code
class Solution:
def solve(self, tasks, k):
freq = Counter(tasks)
Most_freq = freq.most_common()[0][1]
Found_most = sum([freq[key] == Most_freq for key in freq])
return max(len(tasks), (Most_freq - 1) * (k + 1) + Found_most)