Overlapping Rectangles

Problem Given two axis-parallel rectangles by their top-left and bottom-right corners (L1,R1 and L2,R2), determine whether they overlap; sharing an edge counts as overlapping.

Input / Output

  • Input: points L1, R1, L2, R2 (each with x, y).
  • Output: boolean.

Constraints

  • O(1) — this is a logic question, not an algorithms question; getting the conditions and inclusivity right is the test.

Example

  • L1=(0,10), R1=(10,0), L2=(5,5), R2=(15,0) → true. L2=(11,10), R2=(20,0) → false (strictly to the right).
asked …
LeaderboardSalaryAccount