Simple using Sorting and Count


#1

int Solution::solve(vector<vector > &A)
{
int count = 0;
int max_count = 0;
vector<pair<int,int>> Meetings;
for(auto x:A)
{
Meetings.push_back({x[0],0});
Meetings.push_back({x[1],1});
}
auto func = [](pair<int,int> p1,pair<int,int> p2)
{
if(p1.first < p2.first)
return true;
return p1.first == p2.first && p1.second == 1;
};
sort(A.begin(),A.end(),func);
for(int i=0;i<Meetings.size();++i)
{
if(Meetings[i].second == 0)
{
++count;
if(count > max_count)
max_count = count;
}
else
–count;
}
return max_count;
}