-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathn_meetings_in_a_room.cp
58 lines (47 loc) · 1.14 KB
/
n_meetings_in_a_room.cp
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//{ Driver Code Starts
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
class Solution {
public:
bool static compare(pair<int,int> a, pair<int,int> b){
if(a.second < b.second){
return true;
}return false;
}
int maxMeetings(int n, int start[], int end[]) {
vector<pair<int,int>> v;
for(int i=0;i<n;i++){
v.push_back({start[i], end[i]});
}
sort(v.begin(), v.end(), compare);
int last = v[0].second;
int cnt = 1;
for(int i=1;i<v.size();i++){
if(v[i].first > last){
cnt++;
last = v[i].second;
}
}
return cnt;
}
};
//{ Driver Code Starts.
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int start[n], end[n];
for (int i = 0; i < n; i++)
cin >> start[i];
for (int i = 0; i < n; i++)
cin >> end[i];
Solution ob;
int ans = ob.maxMeetings(n, start, end);
cout << ans << endl;
}
return 0;
}
// } Driver Code Ends