-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution2402.py
More file actions
23 lines (23 loc) · 829 Bytes
/
Solution2402.py
File metadata and controls
23 lines (23 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from typing import List
from operator import itemgetter
import collections
class Solution:
def mostBooked(self, n: int, meetings: List[List[int]]) -> int:
book = [0]*n
cnt = [0]*n
for start, end in sorted(meetings,key=itemgetter(0)):
freeBooked = False
nextBooked = [book[0],0]
for i in range(n):
if book[i] <= start:
book[i] = end
cnt[i]+=1
freeBooked = True
break
elif book[i] < nextBooked[0]:
nextBooked[0] = book[i]
nextBooked[1] = i
if freeBooked == False:
book[nextBooked[1]] = nextBooked[0] + (end-start)
cnt[nextBooked[1]] +=1
return cnt.index(max(cnt))