-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinimum_Platforms.cpp
More file actions
55 lines (47 loc) · 861 Bytes
/
Minimum_Platforms.cpp
File metadata and controls
55 lines (47 loc) · 861 Bytes
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
int findPlatform(int arr[], int dep[], int n)
{
sort(arr, arr+n);
sort(dep, dep+n);
int i = 0, j = 0, result = 0, pt = 0;
while(i < n && j < n)
{
if(arr[i] <= dep[j])
{
pt++;
i++;
}
else
{
pt--;
j++;
}
result = max(result, pt);
}
return result;
}
// { 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];
}
cout <<findPlatform(arr, dep, n)<<endl;
}
return 0;
} // } Driver Code Ends