Order N solution.. No sorting needed


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

for(vector<int> v: A){

int count = 0; 
int maxCount = 0;

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



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


good solution bro, nice thinking


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