2019 Dec Silver Problem 2 Meetings
Jump to navigation
Jump to search
Official Problem Statement[edit]
Problem Statement:
Given a set of N meetings, each with a start time and an end time, determine the maximum number of meetings that can take place simultaneously.
Solution:
The solution to this problem is to use a greedy approach. We can sort the meetings by their start time, and then iterate through them. For each meeting, if its start time is after the end time of the previous meeting, then we can add it to the maximum number of meetings that can take place simultaneously. Otherwise, we can ignore it.
In C++, the solution can be implemented as follows:
int maxMeetings(vector<pair<int, int>> meetings) { sort(meetings.begin(), meetings.end()); int maxMeetings = 0; int prevEndTime = 0; for (auto meeting : meetings) { if (meeting.first >= prevEndTime) { maxMeetings++; prevEndTime = meeting.second; } } return maxMeetings; }