forked from aayushi1499/Hacktoberfest2021-DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminimunm_platforms.cpp
55 lines (47 loc) · 1.02 KB
/
minimunm_platforms.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Program to find minimum number of platforms
// required on a railway station
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
class Solution{
public:
//Function to find the minimum number of platforms required at the
//railway station such that no train waits.
int findPlatform(int arr[], int dep[], int n)
{
sort(arr,arr+n);
sort(dep,dep+n);
int pt_no=1;
int j=0;
int i=1;
while(i<n){
if(arr[i]<=dep[j]){
pt_no++;
}else{
j++;
}
i++;
}
return pt_no;
}
};
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int arr[n];
int dep[n];
for(int i=0;i<n;i++)
cin>>arr[i];
for(int j=0;j<n;j++){
cin>>dep[j];
}
Solution ob;
cout <<ob.findPlatform(arr, dep, n)<<endl;
}
return 0;
}