Matej Focko
92c153c768
URL: https://leetcode.com/problems/divide-intervals-into-minimum-number-of-groups/ Signed-off-by: Matej Focko <me@mfocko.xyz>
27 lines
576 B
Go
27 lines
576 B
Go
package main
|
|
|
|
func minGroups(intervals [][]int) int {
|
|
minStart, maxEnd := intervals[0][0], intervals[0][1]
|
|
for _, interval := range intervals {
|
|
start, end := interval[0], interval[1]
|
|
|
|
minStart = min(minStart, start)
|
|
maxEnd = max(maxEnd, end)
|
|
}
|
|
|
|
hits := make([]int, maxEnd+2)
|
|
for _, interval := range intervals {
|
|
start, end := interval[0], interval[1]
|
|
hits[start]++
|
|
hits[end+1]--
|
|
}
|
|
|
|
concurrent, maxConcurrent := 0, 0
|
|
for i := minStart; i <= maxEnd; i++ {
|
|
concurrent += hits[i]
|
|
|
|
maxConcurrent = max(maxConcurrent, concurrent)
|
|
}
|
|
|
|
return maxConcurrent
|
|
}
|