Guest User

Untitled

a guest
Mar 12th, 2024
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. def solve(input):
  2.   input = sorted(input)
  3.   result = []
  4.   while len(input) > 0:
  5.     base = input.pop(0)
  6.     while len(input) > 0 and input[0][0] <= base[1] + 1:
  7.       base = [base[0], max(base[1], input[0][1])]
  8.       input.pop(0)
  9.     result.append(base)
  10.   return result
  11.  
  12. print(solve([[1, 3], [4, 6], [5, 8], [12, 17], [20, 23], [6, 9], [22, 25], [13, 15]]))
Advertisement
Add Comment
Please, Sign In to add comment