fork download
  1. My 2 pointer approach
  2.  
  3. i=j=0;
  4. while(i<n&&j<m)
  5. {
  6. if(a[i]-k<=b[j]&&b[j]<=a[i]+k)
  7. {
  8. j++;
  9. i++;
  10. ans++;//jth apartment given to i applicant
  11. }
  12. else if(b[j]<=a[i]-k)
  13. {
  14. j++;//b[j] cannot be given to anybody from i to n-1
  15. }
  16. else if(b[j]>=a[i]+k)
  17. {
  18. i++;//a[i] cannot get any apartment from b[j] to m-1
  19. //and j 0 to j-1 are already given
  20. }
  21. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:1: error: ‘My’ does not name a type
 My 2 pointer approach
 ^~
prog.cpp:4:1: error: expected unqualified-id before ‘while’
 while(i<n&&j<m)
 ^~~~~
stdout
Standard output is empty