added merge overlapping subintervals

pull/948/head
Dineshwar Doddapaneni 2022-10-06 14:05:46 +05:30
parent 6b7530c587
commit a9e7c67c72
1 changed files with 10 additions and 0 deletions

View File

@ -0,0 +1,10 @@
arr = [[1,2],[0,1],[3,4],[4,6],[9,10]]
arr.sort(key = lambda x : x[0])
m = []
for i in range(len(arr)):
if m==[] or m[-1][1] < arr[i][0]:
v=[arr[i][0],arr[i][1]]
m.append(v)
else:
m[-1][1] = max(m[-1][1],arr[i][1])
print(*m)