Order N solution.. No sorting needed


#1

int Solution::solve(vector<vector > &A) {
map<int,int> mp;

for(vector<int> v: A){
    mp[v[0]]++;
    mp[v[1]]--;
}

int count = 0; 
int maxCount = 0;

for(pair<int,int> pr:mp){
    count += pr.second;
    maxCount = max(maxCount, count);
}
return maxCount;

}


#2

It’s O(Nlg(N)), inserting into map is O(lg(N)); its O(1) for hash_map


#3

good solution bro, nice thinking


#4

Yes it is o(nlogn) as you use Treemap and not hashmap to keep time values sorted.