Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ece0ac4

Browse files
committed
Sync LeetCode submission Runtime - 94 ms (14.45%), Memory - 36.3 MB (58.17%)
1 parent 679440d commit ece0ac4

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<p>You are given an integer <code>eventTime</code> denoting the duration of an event, where the event occurs from time <code>t = 0</code> to time <code>t = eventTime</code>.</p>
2+
3+
<p>You are also given two integer arrays <code>startTime</code> and <code>endTime</code>, each of length <code>n</code>. These represent the start and end time of <code>n</code> <strong>non-overlapping</strong> meetings, where the <code>i<sup>th</sup></code> meeting occurs during the time <code>[startTime[i], endTime[i]]</code>.</p>
4+
5+
<p>You can reschedule <strong>at most</strong> <code>k</code> meetings by moving their start time while maintaining the <strong>same duration</strong>, to <strong>maximize</strong> the <strong>longest</strong> <em>continuous period of free time</em> during the event.</p>
6+
7+
<p>The <strong>relative</strong> order of all the meetings should stay the<em> same</em> and they should remain non-overlapping.</p>
8+
9+
<p>Return the <strong>maximum</strong> amount of free time possible after rearranging the meetings.</p>
10+
11+
<p><strong>Note</strong> that the meetings can <strong>not</strong> be rescheduled to a time outside the event.</p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong class="example">Example 1:</strong></p>
15+
16+
<div class="example-block">
17+
<p><strong>Input:</strong> <span class="example-io">eventTime = 5, k = 1, startTime = [1,3], endTime = [2,5]</span></p>
18+
19+
<p><strong>Output:</strong> <span class="example-io">2</span></p>
20+
21+
<p><strong>Explanation:</strong></p>
22+
23+
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/12/21/example0_rescheduled.png" style="width: 375px; height: 123px;" /></p>
24+
25+
<p>Reschedule the meeting at <code>[1, 2]</code> to <code>[2, 3]</code>, leaving no meetings during the time <code>[0, 2]</code>.</p>
26+
</div>
27+
28+
<p><strong class="example">Example 2:</strong></p>
29+
30+
<div class="example-block">
31+
<p><strong>Input:</strong> <span class="example-io">eventTime = 10, k = 1, startTime = [0,2,9], endTime = [1,4,10]</span></p>
32+
33+
<p><strong>Output:</strong> <span class="example-io">6</span></p>
34+
35+
<p><strong>Explanation:</strong></p>
36+
37+
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/12/21/example1_rescheduled.png" style="width: 375px; height: 125px;" /></p>
38+
39+
<p>Reschedule the meeting at <code>[2, 4]</code> to <code>[1, 3]</code>, leaving no meetings during the time <code>[3, 9]</code>.</p>
40+
</div>
41+
42+
<p><strong class="example">Example 3:</strong></p>
43+
44+
<div class="example-block">
45+
<p><strong>Input:</strong> <span class="example-io">eventTime = 5, k = 2, startTime = [0,1,2,3,4], endTime = [1,2,3,4,5]</span></p>
46+
47+
<p><strong>Output:</strong> <span class="example-io">0</span></p>
48+
49+
<p><strong>Explanation:</strong></p>
50+
51+
<p>There is no time during the event not occupied by meetings.</p>
52+
</div>
53+
54+
<p>&nbsp;</p>
55+
<p><strong>Constraints:</strong></p>
56+
57+
<ul>
58+
<li><code>1 &lt;= eventTime &lt;= 10<sup>9</sup></code></li>
59+
<li><code>n == startTime.length == endTime.length</code></li>
60+
<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>
61+
<li><code>1 &lt;= k &lt;= n</code></li>
62+
<li><code>0 &lt;= startTime[i] &lt; endTime[i] &lt;= eventTime</code></li>
63+
<li><code>endTime[i] &lt;= startTime[i + 1]</code> where <code>i</code> lies in the range <code>[0, n - 2]</code>.</li>
64+
</ul>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def maxFreeTime(
3+
self, eventTime: int, k: int, startTime: List[int], endTime: List[int]
4+
) -> int:
5+
n = len(startTime)
6+
res = 0
7+
t = 0
8+
for i in range(n):
9+
t += endTime[i] - startTime[i]
10+
left = 0 if i <= k - 1 else endTime[i - k]
11+
right = eventTime if i == n - 1 else startTime[i + 1]
12+
res = max(res, right - left - t)
13+
if i >= k - 1:
14+
t -= endTime[i - k + 1] - startTime[i - k + 1]
15+
return res

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /