Learn DSA
Depth-First Search
Greedy Algorithms
Intervals
Can Attend Meetings
easy
DESCRIPTION (credit Leetcode.com)
Write a function to check if a person can attend all the meetings scheduled without any time conflicts. Given an array intervals, where each element [s1, e1] represents a meeting starting at time s1 and ending at time e1, determine if there are any overlapping meetings. If there is no overlap between any meetings, return true; otherwise, return false.
Note that meetings ending and starting at the same time, such as (0,5) and (5,10), do not conflict.
Input:
Output:
Explanation: The meetings (1,5) and (3,9) overlap.
Input:
Output:
true
Explanation: There are no overlapping meetings, so the person can attend all.
💻 Desktop Required
The code editor works best on larger screens. Please open this page on your computer to write and run code.
"Write a function that takes a list of intervals `intervals` and returns `True` if a person can attend all meetings, otherwise returns `False`. An interval is represented by a tuple [start, end]."
Run your code to see results here
Have suggestions or found something wrong?
Explanation
Solution
def canAttendMeetings(intervals):intervals.sort(key=lambda x: x[0])for i in range(1, len(intervals)):if intervals[i][0] < intervals[i - 1][1]:return Falsereturn True
can attend meetings
0 / 5
Complexity Analysis
Login to track your progress
Your account is free and you can post anonymously if you choose.