![]() |
VOOZH | about |
Given n meetings in the form of start[] and end[], where start[i] is the start time of ith meeting and end[i] is the end time of ith meeting. The task is to find the maximum number of meetings that can be scheduled in a single room. The meeting room can have only one meeting at a particular time.
Note: The start time of one chosen meeting can't be equal to the end time of any other chosen meeting.
Examples:
Input: start[] = [1, 3, 0, 5, 8, 5], end[] = [2, 4, 6, 7, 9, 9]
Output: 1 2 4 5
Explanation: We can attend the 1st meeting from (1 to 2), then the 2nd meeting from (3 to 4), then the 4th meeting from (5 to 7), and the 5th meeting from (8 to 9).Input: start[] = [10, 12, 20], end[] = [20, 25, 30]
Output: 1
Explanation: We can attend at most one meeting in a single meeting room.
The idea is to select the maximum number of non-overlapping meetings using a greedy strategy.
- We always pick the meeting that finishes earliest so that we get more room to schedule remaining meetings.
- By sorting meetings based on their finish time, we ensure that at each step we choose the best possible meeting that leaves maximum time for others.
Steps
(finish time, index) pairs and sort meetings based on finish time lastFinish = finish time of first meetingstart > lastFinish, select meeting and Update lastFinishBelow is the implementation of the above approach.
1 2 4 5