VOOZH about

URL: https://www.geeksforgeeks.org/dsa/meeting-rooms-check-if-a-person-can-attend-all-meetings/

⇱ Meeting Rooms - Check if a person can attend all meetings - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Meeting Rooms - Check if a person can attend all meetings

Last Updated : 15 Jul, 2025

Given a 2D array arr[][] where arr[i][0] represents the starting time and arr[i][1] represents the ending time of the ith meeting, determine whether it is possible for a person to attend all meetings without any overlaps, considering that a person can attend only one meeting at any given time.

Note: A person can also attend a meeting if it's starting time is same as the previous meeting's ending time.

Examples:

Input: arr[][] = [[2, 4], [1, 2], [7, 8], [5, 6], [6, 8]]
Output: false
Explanation: Since the third and fifth meeting overlap, a person cannot attend all the meetings.

Input: arr[][] = [[1, 4], [10, 15], [7, 10]]
Output: true
Explanation: Since all the meetings are held at different times, it is possible to attend all the meetings.

[Naive Approach] By checking all pairs of meetings - O(n^2) Time and O(1) Space

A person won't be able to attend all the meetings if any two meetings overlap with each other. So, we can use nested loops to iterate over all pairs of meetings and check if any pair of meetings overlap with each other. If no meetings overlap, then it is possible to attend all the meetings, else it is impossible to attend all the meetings.


Output
false

[Expected Approach] Using Sorting - O(n*log(n)) Time and O(1) Space

Check whether all meetings can be attended without time conflicts by first sorting the meeting intervals based on their start times. After sorting, it compares each meeting's end time with the next meeting's start time to detect any overlaps. If an overlap is found, it returns false, indicating a scheduling conflict. Otherwise, it returns true, meaning all meetings can be attended without overlaps.



Output
false
Comment
Article Tags: