Untitled

 avatar
unknown
plain_text
a year ago
1.1 kB
0
Indexable
class Solution {
public:
    static bool cmp(vector<int>&a ,vector<int>&b){
        if(a[0]==b[0]) return a[1]>=b[1];
        return a[0]<b[0];
    }
    int numberOfPairs(vector<vector<int>>& pts) {
        sort(pts.begin(),pts.end(),cmp);
        int n=pts.size();
        int cnt=0;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                if(i!=j && pts[i][0]<=pts[j][0] && pts[i][1]>=pts[j][1]){
                    bool pres=false;
                    for(int k=0;k<n;k++){ // k is no of ts between i and j
                        if(k==i || k==j) continue;
                        if( pts[k][0]>=pts[i][0] && pts[k][0]<=pts[j][0] && (pts[k][1]>=pts[j][1] && pts[k][1]<=pts[i][1])) 
                            {pres=true; 
                            cout<<"("<<pts[k][0]<<","<<pts[k][1]<<")"<<" \n";
                            break;
                        }
                    }
                    if(pres==false) cnt++;
                }
            }
        }
        
        for(auto i:pts) cout<<"("<<i[0]<<","<<i[1]<<")"<<" ";
        cout<<"\n";

        return cnt;
    }
};
Leave a Comment