Skip to content

Commit b2652be

Browse files
authored
Create m1229.py Weekly Prem
1 parent 524e7d8 commit b2652be

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

my-submissions/m1229.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution:
2+
def minAvailableDuration(self, slots1: List[List[int]], slots2: List[List[int]], duration: int) -> List[int]:
3+
# Since inputs aren't sorted by time period order
4+
# NOTE: x[1] not needed since input is guarenteed not
5+
# to contain overlapping times within the same slot list
6+
slots1.sort(key=lambda x: x[0])
7+
slots2.sort(key=lambda x: x[0])
8+
9+
indx1, indx2 = 0, 0
10+
while indx1 < len(slots1) and indx2 < len(slots2) :
11+
s1, e1, s2, e2 = slots1[indx1] + slots2[indx2]
12+
13+
# Calculate middle gap
14+
if min(e1, e2) - max(s1, s2) >= duration :
15+
return [max(s1, s2), max(s1, s2) + duration]
16+
17+
# Keep the period that ends later
18+
if e1 < e2 :
19+
indx1 += 1
20+
else :
21+
indx2 += 1
22+
23+
# None found
24+
return []

0 commit comments

Comments
 (0)