Class Solution
java.lang.Object
g2201_2300.s2244_minimum_rounds_to_complete_all_tasks.Solution
2244 - Minimum Rounds to Complete All Tasks.<p>Medium</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>tasks</code>, where <code>tasks[i]</code> represents the difficulty level of a task. In each round, you can complete either 2 or 3 tasks of the <strong>same difficulty level</strong>.</p>
<p>Return <em>the <strong>minimum</strong> rounds required to complete all the tasks, or</em> <code>-1</code> <em>if it is not possible to complete all the tasks.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> tasks = [2,2,3,3,2,4,4,4,4,4]</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong> To complete all the tasks, a possible plan is:</p>
<ul>
<li>
<p>In the first round, you complete 3 tasks of difficulty level 2.</p>
</li>
<li>
<p>In the second round, you complete 2 tasks of difficulty level 3.</p>
</li>
<li>
<p>In the third round, you complete 3 tasks of difficulty level 4.</p>
</li>
<li>
<p>In the fourth round, you complete 2 tasks of difficulty level 4.</p>
</li>
</ul>
<p>It can be shown that all the tasks cannot be completed in fewer than 4 rounds, so the answer is 4.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> tasks = [2,3,3]</p>
<p><strong>Output:</strong> -1</p>
<p><strong>Explanation:</strong> There is only 1 task of difficulty level 2, but in each round, you can only complete either 2 or 3 tasks of the same difficulty level. Hence, you cannot complete all the tasks, and the answer is -1.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= tasks.length <= 10<sup>5</sup></code></li>
<li><code>1 <= tasks[i] <= 10<sup>9</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minimumRounds
public int minimumRounds(int[] tasks)
-