-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMeeting_Rooms.cpp
35 lines (32 loc) · 976 Bytes
/
Meeting_Rooms.cpp
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
class Solution {
public:
int mostBooked(int n, vector<vector<int>>& meetings) {
vector<int> ans(n,0);
vector< long long > times(n,0);
sort(meetings.begin(),meetings.end());
for(int i=0;i<meetings.size();i++){
int start = meetings[i][0], end = meetings[i][1];
bool flag = false;
int minind = -1;
long long val = 1e18;
for(int j=0;j<n;j++){
if(times[j]<val) val = times[j], minind = j;
if(times[j] <= start){
flag = true;
ans[j]++;
times[j] = end;
break;
}
}
if(!flag){
ans[minind]++;
times[minind]+=(1ll*(end-start));
}
}
int maxi = -1, id = -1;
for(int i =0;i<n;i++){
if(ans[i]>maxi) maxi = ans[i], id = i;
}
return id;
}
};