Last active
November 27, 2020 18:24
-
-
Save folksilva/46a756979a4b4cedc841fbeb3193f181 to your computer and use it in GitHub Desktop.
Daily Coding Problem: Problem #21
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This problem was asked by Snapchat. | |
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. | |
https://dailycodingproblem.com/ | |
""" | |
import itertools | |
def minimum_rooms(lectures): | |
input_data = [' '.join(str(j) for j in i) for i in lectures] | |
combinations = set() | |
rooms = 0 | |
for c in itertools.combinations(input_data, 2): | |
a = set(range(*(int(n) for n in c[0].split()))) | |
b = set(range(*(int(i) for i in c[1].split()))) | |
if not a.intersection(b) == set(): | |
rooms += 1 | |
return rooms if rooms > 0 else 1 | |
if __name__ == "__main__": | |
# Read the number of lines to read | |
rows = int(input()) | |
lectures = [] | |
for i in range(rows): | |
lectures.append([int(n) for n in input().split()]) | |
print(minimum_rooms(lectures)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please explain the ques.