Advertisement
Rohit4Pal

Untitled

Aug 22nd, 2021
1,086
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. class Solution
  2. {
  3.     public:
  4.     //Function to find the maximum number of meetings that can
  5.     //be performed in a meeting room.
  6.     int maxMeetings(int start[], int end[], int n){
  7.        
  8.         vector<vector<int>> arr(n,vector<int>(2,0));
  9.         for(int i=0;i<n;i++)
  10.             arr[i][0]=start[i],arr[i][1]=end[i];
  11.            
  12.         sort(arr.begin(),arr.end(),compare);
  13.         int meeting=1,currTime=arr[0][1];
  14.        
  15.         for(int i=1;i<n;i++){
  16.             if(arr[i][0]>currTime){
  17.                 meeting++;
  18.                 currTime=arr[i][1];
  19.             }
  20.         }
  21.         return meeting;
  22.     }
  23.     static bool compare(vector<int> a,vector<int> b){
  24.         return a[1]<b[1] || (a[1]==b[1] && a[0]<b[0]);
  25.     }
  26. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement