Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //{ 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
- vector<pair<int,int>> v(n);
- for(int i=0;i<n;i++)
- {
- v[i]={arr[i],dep[i]};
- }
- sort(v.begin(),v.end());
- priority_queue<int,vector<int>,greater<int>> q;
- q.push(v[0].second);
- int c=1;
- for(int i=1;i<n;i++)
- {
- if(q.top()>=v[i].first)
- {
- c++;
- }
- else
- {
- q.pop();
- }
- q.push(v[i].second);
- }
- return c;
- }
- };
- //{ 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
- https://practice.geeksforgeeks.org/problems/minimum-platforms-1587115620/
Add Comment
Please, Sign In to add comment