-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathproblem_1.py
39 lines (31 loc) · 939 Bytes
/
problem_1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""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.
"""
def find_small(array):
mina = array[0][0]
index = 0
for ind in range(len(array)):
if array[ind][0] < mina:
index = ind
return index
def big_all(value, array):
result = True
for i in array:
if i > value:
result = False
return result
intervals = [(30, 75), (0, 50), (60, 150)]
mins = []
for i in intervals:
if len(mins) == 0:
var = find_small(intervals)
mins.append(intervals[var][1])
del intervals[var]
else:
var = find_small(intervals)
if not big_all(intervals[var][0], mins):
mins.append(intervals[var][0])
del intervals[var]
print(len(mins))