Advertisement
nathaditya

Untitled

Feb 23rd, 2024
1,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 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 <pair<int,int>> vec;
  9.         for(int i = 0 ; i < n; i++){
  10.             vec.push_back({start[i],end[i]});
  11.         }
  12.        
  13.         auto comp = [](pair<int,int> a, pair<int,int> b){
  14.             if(a.second != b.second)
  15.                 return(a.second < b.second);
  16.                
  17.             return(a.first < b.first);
  18.         };
  19.        
  20.         sort(vec.begin(), vec.end(), comp);
  21.         int en = -1;
  22.         int ctr = 0;
  23.         for(int i = 0; i < n; i++){
  24.             if(vec[i].first > en){
  25.                 ctr++;
  26.                 en = vec[i].second;
  27.             }
  28.         }
  29.  
  30.         return ctr;
  31.     }
  32. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement