Please explain briefly

how do we use sort in vector<pair<int,int>>v using compare function in c++…

seee u are sending
pair<int,int> for sorting purpose
if u need to sort acc to 2nd value of pair then
thecode will be something like
so bool cmp(pair<int,int> a , pair<int,int> b){
if(a.second > b.second) return true; // since decreasing order is required so the first pair with greater second index should come first
else return a.first < b.first; // else return the one with smaller first index in case the seconds of the pair are equal
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.