N Meetings in One Room

Intervals and Scheduling DSA practice problem on Onlearn.

Difficulty: medium.

Topics: Maximum number of non-overlapping meetings in a single meeting room (Meeting Room Scheduling Problem), Greedy Algorithm, Sorting, Interval Scheduling, space complexity, greedy algorithm, sorting algorithms, intervals, time complexity analysis, N meetings in one room / Activity Selection.

Problem Statement There is one meeting room in a firm. You are given $N$ meetings in the form of two arrays, start and end, where start[i] is the start time of the $i^{th}$ meeting and end[i] is the end time of the $i^{th}$ meeting. The goal is to find the maximum number of meetings that can be accommodated in the single meeting room. Note: 1. A meeting cannot be attended if it overlaps with another selected meeting. 2. A meeting ending at time $T$ is considered to overlap with a meeting starting at time $T$. Therefore, the start time of the next meeting must be strictly greater than the end time of the previous meeting. Input Specification First line contains an integer array representing the start times (space separated). Second line contains an integer array representing the end times (space separated). Both arrays are of the same length $N$. Output Specification Return a single integer representing the maximum number of meetings that can be held. Constraints $1 \le N \le 10^5$ $0 \le \text{start}[i] < \text{end}[i] \le 10^9$ All input values are integers. Sample Test Cases Sample Input 1 Sample Output 1 Explanation: The meetings are: (1, 2), (3, 4), (0, 6), (5, 7), (8, 9), (5, 9). We can select the meetings (1, 2), (3, 4), (5, 7), and (8, 9) to get a maximum of 4 non overlapping meetings. Sample Input 2 Sample Output 2 Explanation: The meetings are (10, 20), (12, 25), and (20, 30). If we pick (10, 20), we cannot pick (12, 25) because $12 < 20$. We also cannot pick (20, 30) because the start time $20$ is not strictly greater than the previous end time $20$. If we pick (12, 25), we can only hold 1 meeting. If we pick (20, 30), we can only hold 1 meeting. Maximum meetings = 1. Difficulty Level Medium