Skip to content

Commit 0994457

Browse files
authored
Create 2406.divide-intervals-into-minimum-number-of-groups.js
1 parent a9f28a4 commit 0994457

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @param {number[][]} intervals
3+
* @return {number}
4+
*/
5+
var minGroups = function(intervals) {
6+
const hash = {}
7+
for(let [s, e] of intervals) {
8+
e = e + 1
9+
hash[s] = (hash[s] || 0) + 1
10+
hash[e] = (hash[e] || 0) - 1
11+
}
12+
let res = 0, cur = 0
13+
const keys = Object.keys(hash).map(e => +e)
14+
keys.sort((a, b) => a - b)
15+
for(const k of keys) {
16+
cur += hash[k]
17+
res = Math.max(res, cur)
18+
}
19+
return res
20+
};

0 commit comments

Comments
 (0)