Isaac Emmanuel
09 Sept 2026•EasyGo / Python / TypeScript

Rectangle Overlap

Determine whether two axis-aligned rectangles overlap with positive area.

The rectangles fail to overlap only when one is completely left, right, above, or below the other; negate those separation cases.

Complexity

O(1) time and O(1) space.

Solution files

Go•rectangle-overlap/solution.go
package main

func isRectangleOverlap(rec1 []int, rec2 []int) bool {
	return rec1[0] < rec2[2] && rec2[0] < rec1[2] && rec1[1] < rec2[3] && rec2[1] < rec1[3]
}
Python•rectangle-overlap/solution.py
class Solution:
    def isRectangleOverlap(self, rec1: list[int], rec2: list[int]) -> bool:
        return rec1[0] < rec2[2] and rec2[0] < rec1[2] and rec1[1] < rec2[3] and rec2[1] < rec1[3]
TypeScript•rectangle-overlap/solution.ts
function isRectangleOverlap(rec1: number[], rec2: number[]): boolean {
  return rec1[0] < rec2[2] && rec2[0] < rec1[2] && rec1[1] < rec2[3] && rec2[1] < rec1[3];
}