Skip to content

Commit 5f86060

Browse files
authored
Create 3439.swift
1 parent af63386 commit 5f86060

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

3001-3500/3439.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
func maxFreeTime(_ eventTime: Int, _ k: Int, _ startTime: [Int], _ endTime: [Int]) -> Int {
3+
let n = startTime.count
4+
var busy = 0
5+
var ans = 0
6+
7+
for i in 0..<k {
8+
busy += endTime[i] - startTime[i]
9+
}
10+
11+
if n == k {
12+
return eventTime - busy
13+
}
14+
15+
ans = startTime[k] - busy
16+
17+
var i = 0
18+
for r in k..<n {
19+
busy += (endTime[r] - startTime[r]) - (endTime[i] - startTime[i])
20+
let end = (r == n - 1) ? eventTime : startTime[r + 1]
21+
let start = endTime[i]
22+
ans = max(ans, end - start - busy)
23+
i += 1
24+
}
25+
26+
return ans
27+
}
28+
}

0 commit comments

Comments
 (0)