You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#Explanation: Because the new interval [4,8] overlaps with [3,5],[6,7],[8,10].
22
+
classSolution:
23
+
definsert(self, intervals, newInterval):
24
+
l, r= [], [] #Initialize l and r empty list
25
+
intervals.sort(key=lambdax:x[0]) #Sort the intervals by its 1st element in sublists
26
+
foriinintervals: #Loop through intervals
27
+
ifi[1] <newInterval[0]: #Condition-check: If i's last element is less than newInterval's first element
28
+
l.append(i) #We append i in l
29
+
elifi[0] >newInterval[1]: #Condition-check: Elif i's first element is greater than newInterval's last element
30
+
r.append(i) #We append i in r
31
+
else:
32
+
newInterval= [min(newInterval[0], i[0]), max(newInterval[1], i[1])] #Update the newInterval by taking min and max of newInterval and i's first and last element resepectively
0 commit comments