Skip to content

Commit 60ce607

Browse files
authored
Create 3439. Reschedule Meetings for Maximum Free Time I
1 parent 8277ed8 commit 60ce607

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Solution {
2+
public:
3+
int maxFreeTime(int eventt, int k, vector<int>& strtt, vector<int>& endt) {
4+
int n = strtt.size();
5+
vector<int> gaps(n+1, 0);
6+
7+
gaps[0] = strtt[0];
8+
for(int i=1; i<n; i++){
9+
gaps[i] = strtt[i] - endt[i-1];
10+
}
11+
gaps[n] = eventt - endt[n-1];
12+
13+
for(int ele:gaps) cout<<ele<<" ";
14+
15+
int tmp = 0;
16+
int j=0;
17+
while(j<=k){
18+
tmp += gaps[j];
19+
j++;
20+
}
21+
22+
int ans = tmp;
23+
int i=0;
24+
while(j<=n && i<=n){
25+
tmp -= gaps[i];
26+
i++;
27+
tmp += gaps[j];
28+
j++;
29+
ans = max(ans, tmp);
30+
}
31+
32+
return ans;
33+
34+
}
35+
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy