Question: Flipkart Grid, Recently Asked Online Assessment Questions (28th September 2023) | Coding Friends | Conference Schedule
0
Entering edit mode

0
Entering edit mode

bool sss(pi &A,pi &B){

    if(A.ff == B.ff)return A.ss < B.ss;

    return A.ff < B.ff;

}

void solve(){      

int n;cin>>n;

vi A(n),B(n);

for(int i = 0;i<n;i++)cin>>A[i];

for(int i = 0;i<n;i++)cin>>B[i];

   vpi tt(n);

   for(int i = 0;i<n;i++)tt[i] = {A[i],B[i]};

   sort(tt.begin(),tt.end(),sss);

   int ans = 0;

   int prev = -1;

   for(int i = 0;i<n;i++){

       if(i == 0){

        ans++;

        prev = tt[0].ss;

        continue;

       }

       if(prev <= tt[i].ff){

         ans++;

         prev = tt[i].ss;

       }

   }

   cout<<ans<<'\n';

}

ADD COMMENTlink 13 months ago gender • 10

Login before adding your answer.

Similar Posts
Loading Similar Posts