bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 836. Rectangle Overlap

836. Rectangle Overlap

Leetcode Solutions

Check Position for Rectangle Overlap

  1. Check if either rectangle is a line by seeing if the width or height is zero.
  2. Check if rec1 is to the left of rec2 by comparing if rec1[2] (right side of rec1) is less than or equal to rec2[0] (left side of rec2).
  3. Check if rec1 is to the right of rec2 by comparing if rec1[0] (left side of rec1) is greater than or equal to rec2[2] (right side of rec2).
  4. Check if rec1 is above rec2 by comparing if rec1[1] (bottom side of rec1) is greater than or equal to rec2[3] (top side of rec2).
  5. Check if rec1 is below rec2 by comparing if rec1[3] (top side of rec1) is less than or equal to rec2[1] (bottom side of rec2).
  6. If none of the above checks indicate that rec1 is to the left, right, above, or below rec2, then the rectangles overlap.
UML Thumbnail

Check Area for Rectangle Overlap

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...