Meeting Room Assignment

Problem

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.

input

  • The first line gives the number of meetings n (1<=n<=100,000)
  • From line 2 to line n+1, information of each meeting is given, and the start and end times of the meeting are given with a space in between
  • The condition for the start time and end time of a meeting is (start time <= end time)
5

1 4
2 3
3 5
4 6
5 7

---

3

3 3
1 3
2 3

output

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;

Solution

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;
}