[C++] with comments


#1
int Solution::solve(vector<vector<int> > &a) {
    int n = a.size();
    if(n <= 1)
        return n;
        
    vector<pair<int, int>> arr;
    for(int i=0; i<n; i++){
        arr.push_back({a[i][0], 1});    //mark arrival time as 1
        arr.push_back({a[i][1], 0});    //mark departure time as 0
    }
    sort(arr.begin(), arr.end());
    
    int res = 0, curr = 0, i = 0;
    for(int i=0; i<arr.size(); i++){
        if(arr[i].second == 1){     //count max no of rooms we need
            curr++;
            res = max(curr, res);
        }
        else{
            curr--;
        }
    }
    return res;
}