diff --git a/algorithms/Python/arrays/merge_overlapping_intervals.py b/algorithms/Python/arrays/merge_overlapping_intervals.py new file mode 100644 index 00000000..d281d42a --- /dev/null +++ b/algorithms/Python/arrays/merge_overlapping_intervals.py @@ -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) \ No newline at end of file