Jump to content

Recommended Posts

Posted

why do you complicate things..replace your function with this 

private static boolean intersection2(Rectangle r1, Rectangle r2) {
 float x1 = r1.x + r1.width;
 float y1 = r1.y + r1.height;

 float x2 = r2.x + r2.width;
 float y2 = r2.y + r2.height;

 if (x1 < r2.x || x2 < r1.x)
  return false;

 //up or down
 if (r1.y > y2 || y1 < r2.y)
  return false;
  
return true;
}

 

 

can you please check below code:
 
TEST1 result okkati false ostundi.....
 
 
public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String s= in.readLine() ;
   String b[]=s.split(" ");
   int a[] =new int[8];
 
 for(int i=0;i<a.length;i++)
  a[i]=Integer.parseInt(b[i]);
   Rectangle r1 = new Rectangle(a[0],a[1],a[2],a[3]);
  Rectangle r2 = new Rectangle(a[4],a[5],a[6],a[7]);
  System.out.println(intersection2(r1,r2));
}
 
  private static boolean intersection2(Rectangle r1, Rectangle r2
      ) {
      float xmin = Math.max(r1.x, r2.x);
      float xmax1 = r1.x + r1.width;
      float xmax2 = r2.x + r2.width;
      float xmax = Math.min(xmax1, xmax2);
      if (xmax> xmin) {
          float ymin = Math.max(r1.y, r2.y);
          float ymax1 = r1.y + r1.height;
          float ymax2 = r2.y + r2.height;
          float ymax = Math.min(ymax1, ymax2);
          if (ymax > ymin) {
                   return true;
          }
      }
      return false;
  }

 

 

Posted

:3D_Smiles: time limit...mari chepte call chese vadni kada

thanks mama....time ayepoendi anta...

 

Posted

next time ninne direct ga contact chestha mama..

:3D_Smiles: time limit...mari chepte call chese vadni kada

 

Posted

hacker rank ani ardam iyindi..you could have changed lang to c# and just pasted my sol 

 

these are the results 

0 0 1 1 -1 -1 1 1
True
1 1 1 1 -1 -1 2 1
False
1 1 1 1 -1 -1 3 1
False
1 1 1 1 -1 -1 3 3
True

next time ninne direct ga contact chestha mama..

 

Posted

next time ninne direct ga contact chestha mama..

:giggle: :giggle:
×
×
  • Create New...