package LeetCode_253
import LeetCode_252.Interval
import java.util.Arrays
/**
* 253. Meeting Rooms II
* (Lock by Leetcode)
* https://www.lintcode.com/problem/meeting-rooms-ii/description
* Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei),
* find the minimum number of conference rooms required.
* */
class Solution {
fun minMeetingRooms(intervals: List<Interval>?): Int {
if (intervals == null || intervals.size == 0) {
return 0
}
val size = intervals.size
val starts = IntArray(size)
val ends = IntArray(size)
for (i in 0 until size) {
starts[i] = intervals[i].start
ends[i] = intervals[i].end
}
Arrays.sort(starts)
Arrays.sort(ends)
var room = 0
var endIndex = 0
for (i in 0 until size) {
if (starts[i] < ends[endIndex]) {
room++
} else {
endIndex++
}
}
return room
}
}