greedy December 17, 2022

Minimum rounds to complete all tasks

Time O(n) Space O(n) Open original problem

We will count the different tasks and calculate the number of rounds for each task. Then we will return the maximum number of rounds.

class Solution:
    def minimumRounds(self, tasks: List[int]) -> int:
        counter = collections.Counter(tasks)
        res = 0
        for count in counter.values():
            if count <= 1:
                return -1
            res += math.ceil(count/3)
        return res

Time complexity: O(n)
Space complexity: O(n)