- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterval_schedule.py
More file actions
Latest commit
19 lines (16 loc) · 681 Bytes
/
Copy pathinterval_schedule.py
File metadata and controls
19 lines (16 loc) · 681 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
definterval_scheduling_lecture(lectures: list[dict]) ->list[dict]:
"""
Schedule lectures to maximize the number of lectures that can be attended. This uses the greedy algorithm.
:param lectures: list of lectures
:return: list of scheduled lectures
"""
lectures.sort(key=lambdat: t['start'])
lectures.sort(key=lambdat: t['end'])
scheduled_lectures= []
forindex, lectureinenumerate(lectures):
ifnotscheduled_lectures:
scheduled_lectures.append(lecture)
else:
iflecture['start'] >=scheduled_lectures[-1]['end']:
scheduled_lectures.append(lecture)
returnscheduled_lectures