Conference Room There is one conference room, and we want to create a conference room usage table for n conferences that we want to use.
Find the maximum number of meetings that are given the time and can use the conference room without overlapping each meeting.
However, once a meeting starts, it cannot be stopped in the middle, and the next meeting may start at the same time as one meeting ends.
5
1 4
2 3
3 5
4 6
5 7
---
3
3 3
1 3
2 3
Print the maximum number of available meetings on the first line.
// (2, 3), (3, 5), and (5, 7) can use the conference room.
3;
2;
function solution(meeting) {
let answer = 0,
endTime = 0;
meeting.sort(([s1, e1], [s2, e2]) => e1 - e2 || s1 - s2);
for (let [st, et] of meeting) {
if (st >= endTime) {
answer++;
endTime = et;
}
}
return answer;
}
function solution(meeting) {
let answer = 0;
meeting.sort((a, b) => {
if (a[1] === b[1]) return a[0] - b[0];
else return a[1] - b[1];
});
let et = 0;
for (let x of meeting) {
if (x[0] > et) {
answer++;
et = x[1];
}
}
return answer;
}