Skip to main content

2406.js

/** ------------------------------------------------------------------------------
*
* 2406. Divide Intervals Into Minimum Number of Groups
* Topics: Two Pointer, Heap
* https://leetcode.com/problems/divide-intervals-into-minimum-number-of-groups/description/?envType=daily-question&envId=2024-10-12
*
------------------------------------------------------------------------------ */
/**
* @param {number[][]} intervals
* @return {number}
*/
var minGroups = function (intervals) {
let d = [],
h = 0,
res = 0

for (const [l, r] of intervals) {
d.push([l, 1])
d.push([r + 1, -1])
}
d.sort((x, y) => {
if (x[0] != y[0]) return x[0] - y[0]
return x[1] - y[1]
})

for (const [, mark] of d) {
h += mark
res = Math.max(res, h)
}
return res
}

console.log()