2
* Each round, we can complete either 2 or 3 tasks of the same difficulty level Time: O(n) Space:6
public int minimumRounds(int[] tasks) {8
Map<Integer, Integer> taskMap = new HashMap<>(); // map of <task, number of each task>9
for (int i = 0; i < tasks.length; i++) {10
taskMap.put(tasks[i], taskMap.getOrDefault(tasks[i], 0) + 1);13
for (Map.Entry<Integer, Integer> entry : taskMap.entrySet()) {14
if (entry.getValue() == 1) {15
return -1; // we cannot complete if there is only 1 task17
// try to take as many 3's as possible18
round += entry.getValue() / 3;21
We can have 1 or 2 tasks remaining. We're not supposed to take task of count 1, but we can 'borrow' 1 from the previous22
ex. [5,5,5,5,5,5,5] -> [5,5,5][5,5,5][5]23
In this example, treat the last [5,5,5], [5] as [5,5], [5,5]25
if (entry.getValue() % 3 != 0) {