Leetcode Daily Challenge


I have written the code below and it is not passing all test cases plz help me rectify the code

bool comp(vectorv1,vectorv2){
//starting points se sort
return v1[1]<v2[1];
}

class Solution {
public:
bool carPooling(vector<vector>& trips, int capacity) {
//sort
sort(trips.begin(),trips.end(),comp);
map<int,int>mp;
int curr_cap=0;
int curr_pos;
for(auto it:trips){
int pass=it[0];
int s=it[1];
int e=it[2];
curr_pos=s;
curr_cap+=pass;
//drop passengers
for(auto it:mp){
//if we find an end positon less than curr_pos
if(it.second<=curr_pos){
curr_cap=curr_cap-it.first;
//delete from map
mp.erase(it.first);
}
}
//check if we can take more passengers
if(curr_cap<=capacity){
mp[pass]=e;
}
else{
return false;
}
}
return true;
}
};