-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy path3169-count-days-without-meetings.py
More file actions
40 lines (34 loc) · 1.07 KB
/
3169-count-days-without-meetings.py
File metadata and controls
40 lines (34 loc) · 1.07 KB
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
40
# time complexity: O(nlogn)
# space complexity: O(n)
from typing import List
class Solution:
def countDays(self, days: int, meetings: List[List[int]]) -> int:
meetings.sort()
prev = meetings[0]
mergeList = [prev]
for i in range(1, len(meetings)):
currMeeting = meetings[i]
if prev[1] >= currMeeting[0]:
if prev[1] >= currMeeting[1]:
continue
else:
prev[1] = currMeeting[1]
else:
mergeList.append(currMeeting)
prev = mergeList[-1]
for start, end in mergeList:
days -= (end - start + 1)
return days
days = 34
meetings = [[15, 34], [5, 18], [9, 20], [1, 4],
[6, 30], [6, 28], [25, 30], [23, 24]]
print(Solution().countDays(days, meetings))
days = 10
meetings = [[5, 7], [1, 3], [9, 10]]
print(Solution().countDays(days, meetings))
days = 5
meetings = [[2, 4], [1, 3]]
print(Solution().countDays(days, meetings))
days = 6
meetings = [[1, 6]]
print(Solution().countDays(days, meetings))