Menu Close

Given an array of meeting time intervals consisting of start and end times [[s1,e1]…Fcukthecode

Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],…] (si < ei), determine if a person could attend all meetings.

Example 1:

    Input: [[0,20],[5,10],[20,30]]

    Output: false

Example 2:

    Input: [[4,6],[7,10]

    Output: true
def Meetings(intvals):   
    intvals.sort()
    temp=0
    for i in range(len(intvals)):
    	if temp < intvals[i][0] :
    		if intvals[i][0] > intvals[i][1] :
    			return False
    		else:
    			temp=intvals[i][1]
    	else:
    		return False
    return True

  
Time_inter = input('Time intervals : ')

import ast #Abstract Syntax Tree Module

Time_inter = ast.literal_eval(Time_inter)  #Conversion of string to list

print(Meetings(Time_inter))

Input_1:
Time intervals : [ [0,20], [5,10], [20,30] ]

Output:
False


Input_2:
Time intervals : [ [4,6], [7,10] ]

Output:
True


 


Input_3:
Time intervals : [ [1,2], [3,4], [6,10], [7,20] ]

Output:
False


Input_4:
Time intervals : [ [1,2], [3,4], [6,10], [11,20] ]

Output:
True


ILLUSTRATION

Executed using python3