All problems
Minimum Rounds to Complete Tasks
Problem
Given task difficulty levels, return the minimum number of rounds to complete all tasks, where each round completes either 2 or 3 tasks of the same level, or -1 if any level appears exactly once.
For a level with count c the minimum rounds is (c + 2) // 3, which prefers groups of three. Any singleton makes the schedule impossible.
Hint
Counts of 2 and 3 take one round, and every larger count can be built from 2s and 3s.
Test cases
case 1
in: [[2,2,3,3,2,4,4,4,4,4]]
expected: 4
case 2
in: [[5,5,5,5]]
expected: 2
case 3
in: [[2,3,3]]
expected: -1
case 4
in: [[7,7,7,7,7,7]]
expected: 2
case 5
in: [[1]]
expected: -1
Starter codePython
def min_rounds_tasks(tasks):
# Your code here
pass5 test cases · run your code against them in the editor