forked from shivprime94/Data-Structure-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinimumPlatforms.cpp
More file actions
60 lines (54 loc) · 1.18 KB
/
MinimumPlatforms.cpp
File metadata and controls
60 lines (54 loc) · 1.18 KB
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
59
60
// { Driver Code Starts
// 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)
{
// Your code here
sort(arr,arr+n);
sort(dep,dep+n);
int min_plat=1,need_plat=1;
int i=1,j=0;
while(i<n){
if(arr[i]<=dep[j])
{
i++;
min_plat++;
}
else{
j++;
min_plat--;
}
need_plat=max(min_plat,need_plat);
}
return need_plat;
}
};
// { Driver Code Starts.
// Driver code
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;
} // } Driver Code Ends