Learner Level
Implement the canAttendAllMeetings method that checks whether a person can attend all given meetings.
The input contains a list of meeting intervals intervals and the number of meetings size. Each interval contains a start time and an end time.
Your task is to check whether one person can attend all meetings. This is possible only if no two meetings overlap. Meetings that touch at the boundary, such as one ending at 10 and the next starting at 10, are allowed.
Sort all meetings by their start time.
After sorting, only neighboring meetings need to be compared. If the next meeting starts before the previous meeting ends, the person cannot attend both meetings.
If no overlapping pair is found, all meetings can be attended.
Pseudocode:
function canAttendAllMeetings(intervals, size):
sort intervals by start time
for i from 1 to size - 1:
previousEnd = intervals[i - 1][1]
currentStart = intervals[i][0]
if currentStart < previousEnd:
return false
return true