Skip to content

Commit ee9f19c

Browse files
committed
Add solution #2244
1 parent 8dc4244 commit ee9f19c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@
285285
2099|[Find Subsequence of Length K With the Largest Sum](./2099-find-subsequence-of-length-k-with-the-largest-sum.js)|Medium|
286286
2114|[Maximum Number of Words Found in Sentences](./2114-maximum-number-of-words-found-in-sentences.js)|Easy|
287287
2129|[Capitalize the Title](./2129-capitalize-the-title.js)|Easy|
288+
2244|[Minimum Rounds to Complete All Tasks](./2244-minimum-rounds-to-complete-all-tasks.js)|Medium|
288289
2427|[Number of Common Factors](./2427-number-of-common-factors.js)|Easy|
289290

290291
## License
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* 2244. Minimum Rounds to Complete All Tasks
3+
* https://leetcode.com/problems/minimum-rounds-to-complete-all-tasks/
4+
* Difficulty: Medium
5+
*
6+
* You are given a 0-indexed integer array tasks, where tasks[i] represents the difficulty level
7+
* of a task. In each round, you can complete either 2 or 3 tasks of the same difficulty level.
8+
*
9+
* Return the minimum rounds required to complete all the tasks, or -1 if it is not possible to
10+
* complete all the tasks.
11+
*/
12+
13+
/**
14+
* @param {number[]} tasks
15+
* @return {number}
16+
*/
17+
var minimumRounds = function(tasks) {
18+
const map = new Map();
19+
let result = 0;
20+
21+
tasks.forEach(task => map.set(task, map.has(task) ? map.get(task) + 1 : 1));
22+
23+
for (const count of map.values()) {
24+
if (count < 2) {
25+
return -1;
26+
}
27+
result += Math.floor(count / 3) + (count % 3 === 0 ? 0 : 1);
28+
}
29+
30+
return result;
31+
};

0 commit comments

Comments
 (0)