Answers for "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."

0

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.

def solution(n):
     time_counter = [0 for i in range(1441)]
     for i in n:
         time_counter[i[0]] += 1
         time_counter[i[1]] += -1
     rooms, tmp = 0, 0
     for i in time_counter:
         tmp += i
         if(tmp > rooms):
             rooms = tmp
     return rooms
 print solution([[30, 75], [0, 50], [60, 150]])
 print solution([[30, 75], [0, 50], [60, 150], [30, 75]])
 print solution([])
 print solution([[0, 60]])
Posted by: Guest on June-21-2021

Code answers related to "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."

Browse Popular Code Answers by Language