Snippets Collections
class Solution
{
    public:
    //Function to find the maximum number of meetings that can
    //be performed in a meeting room.
    int maxMeetings(int start[], int end[], int n)
    {
        // Your code here
        using pi = pair<int,int> ;
        vector<pi> vp;
        for(int i = 0; i < n; i++)
            vp.push_back({start[i] , end[i]});
        sort(vp.begin(), vp.end(),[](auto a, auto b){
           return a.second < b.second; 
        });
        int ans = 0, r = INT_MIN;
        for(int  i =0 ; i < n ; i++){
            if(vp[i].first > r){
                ans++;
                r = vp[i].second;
            }
        }
        return ans;
    }
};
star

Thu Jun 08 2023 07:52:02 GMT+0000 (Coordinated Universal Time) https://practice.geeksforgeeks.org/problems/n-meetings-in-one-room-1587115620/1

#n_meetings #greedy #gfg #c++

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension