-
Are all meetings possible?
-
https://www.geeksforgeeks.org/find-maximum-meetings-in-one-room/
-
This problem is to determine if it will be possible to conduct all meetings, in other words are there any colliding intervals.
Intuition
- First sort all intervals based on their start time.
- Initialisation phase loop start with 1 not 0.
- If the first element of current 2 element array is smaller than second element of previous array then return false.
- Termination phase return true.
Code
# Time: O(nlogn)
# Space: O(n)
class Solution(object):
def canAttendMeetings(self, intervals):
"""
:type intervals: List[List[int]]
:rtype: bool
"""
intervals.sort(key=lambda x: x[0])
for i in xrange(1, len(intervals)):
cur_start_time = intervals[i][0]
prev_end_time = intervals[i-1][1]
if cur_start_time < prev_end_time:
return False
return TrueAttempt 1
def solution(arr: [int, int]) -> int:
arr.sort(key = lambda x: x[0])
for i in range(1, len(arr)):
first = arr[i - 1]
second = arr[i]
if first[1] > second[0]:
return False
return True
python_trick to sort my2DArr.sort(key = lambda x: x[0])