Back to course home
0% completed
Vote For New Content
Can we take the approach of finding number of intersections?
Vansh Arora
Aug 26, 2023
Code will be similar to merge intervals, but instead of replacing currentInterval with merged interval, we will set currentInterval to intersection of current and nextInterval.Please see code below and let me know if there are any issues with this approach:
static int findMinimumMeetingRooms(vector<Meeting> &meetings) { sort(meetings.begin(), meetings.end(), [] (const Meeting &first, const Meeting &second) { return first.start < second.start; }); int minRooms = 1, currentRooms = 1; Meeting currentMeeting = meetings[0]; for (int next = 1; next < meetings.size(); next++) { // If there is an overlap if (meetings[next].start < currentMeeting.end) { currentRooms++; // Find intersection and set currentMeeting to the intersection currentMeeting.start = meetings[next].start; currentMeeting.end = min(currentMeeting.end, meetings[next].end); } else { minRooms = max(minRooms, currentRooms); currentMeeting = meetings[next]; currentRooms = 1; } } // For last iteration minRooms = max(minRooms, currentRooms); }
0
0
Comments
Comments
Parikshit Murria8 months ago
This passes the provided test cases but does not cover all the scenarios. Basically, resetting the meeting rooms to 1 even if one meeting ends doesn't seems right.
On this page