Daily Coding Challenge solution – day 21

The Challenge Given an array of time intervals (start, end) for classroom lectures (possibly overlapping), find the minimum number of rooms required.

For example, given [(30, 75), (0, 50), (60, 150)], you should return 2.

I believe this code has no errors but if you find any, please do let me know. Otherwise, feel free to use this solution if you get stuck

My Solution

def item_2(element):     return (element[1]) #Returns second element of tuple for sorting   classes = [(15,50),(51,53),(54,58),(60,70),(61,63),(65,69),(71,83)] #classes = [(30, 75), (0, 50), (60, 150), (0, 500), (40, 70)] classes.sort(key=item_2)  print("The following classes will be needed") while classes:     item = classes[0]     index = 0      end_time = item[1]     remaining = classes[1:]     room_bookings = []     room_bookings.append(item)     for next_item in remaining:         if next_item[0] > end_time:             room_bookings.append(next_item)             classes.remove(next_item)             end_time = next_item[1]     print(room_bookings)     classes.remove(item)