To store the number of points has same x or y coordinates
unordered_map < int , int > xpoints ; unordered_map < int , int > ypoints ; for ( int i = 0 ; i < n ; i ++ ) { xpoints [ a [ i ] [ 0 ] ] ++ ; ypoints [ a [ i ] [ 1 ] ] ++ ; }