C ++ implementation of the above approach
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool compareTo ( pair < int , int > p1 , pair < int , int > p2 ) { return p1 . second < p2 . second ; }