Skip to content

Commit 114e705

Browse files
authored
Create 2244-minimum-rounds-to-complete-all-tasks.js
1 parent 3a1665d commit 114e705

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @param {number[]} tasks
3+
* @return {number}
4+
*/
5+
const minimumRounds = function(tasks) {
6+
let res = 0
7+
const hash = {}
8+
for(let e of tasks) {
9+
if(hash[e] == null) hash[e] = 0
10+
hash[e]++
11+
}
12+
const keys = Object.keys(hash).map(e => +e)
13+
for(const k of keys) {
14+
if(hash[k] / 3 >= 1) res += ~~(hash[k] / 3)
15+
if(hash[k] % 3 === 2) res++
16+
if(hash[k] % 3 === 1) {
17+
if(hash[k] >= 4) res++
18+
else return -1
19+
}
20+
}
21+
22+
return res
23+
};

0 commit comments

Comments
 (0)