Minimum Rounds to Complete All Tasks
You are given a 0-indexed integer array tasks, where tasks[i] represents the difficulty level of a task. In each round, you can complete either 2 or 3 tasks of the same difficulty level.
Return the minimum rounds required to complete all the tasks, or -1 if it is not possible to complete all the tasks.
Note: This question is the same as 2870: Minimum Number of Operations to Make Array Empty.
Example 1
Input
tasks = [2,2,3,3,2,4,4,4,4,4]Output
4A possible optimal plan uses one round for three tasks of difficulty 2, one round for two tasks of difficulty 3, and two rounds for all five tasks of difficulty 4, for a total of 4 rounds.
Example 2
Input
tasks = [2,3,3]Output
-1There is only 1 task of difficulty level 2, but each round must complete either 2 or 3 tasks of the same difficulty level, so all tasks cannot be completed.
Constraints
- 1 <= tasks.length <= 10^5
- 1 <= tasks[i] <= 10^9