Minimum rounds to complete all tasks

December 17, 2022

greedy

Problem URL: Minimum rounds to complete all tasks

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)