An axis-aligned rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) is the coordinate of its bottom-left corner, and (x2, y2) is the coordinate of its top-right corner. Its top and bottom edges are parallel to the X-axis, and its left and right edges are parallel to the Y-axis.
Two rectangles overlap if the area of their intersection is positive. To be clear, two rectangles that only touch at the corner or edges do not overlap.
Given two axis-aligned rectangles rec1 and rec2, return true if they overlap, otherwise return false.
 
Example 1:
Input: rec1 = [0,0,2,2], rec2 = [1,1,3,3]
Output: true
Example 2:
Input: rec1 = [0,0,1,1], rec2 = [1,0,2,1]
Output: false
Example 3:
Input: rec1 = [0,0,1,1], rec2 = [2,2,3,3]
Output: false

 
Constraints:

rect1.length == 4
rect2.length == 4
-109 <= rec1[i], rec2[i] <= 109
rec1[0] <= rec1[2] and rec1[1] <= rec1[3]
rec2[0] <= rec2[2] and rec2[1] <= rec2[3]

Difficulty: EASY
Tags: Geometry

Mathematics

Starter code:
class Solution:
    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:
        

Solutions:
class Solution:

	def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:
		return not (rec1[0] >= rec2[2] or rec1[2] <= rec2[0] or rec1[1] >= rec2[3] or (rec1[3] <= rec2[1]))


class Solution:

	def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:
		r1x1 = rec1[0]
		r1y1 = rec1[1]
		r1x2 = rec1[2]
		r1y2 = rec1[3]
		r2x1 = rec2[0]
		r2y1 = rec2[1]
		r2x2 = rec2[2]
		r2y2 = rec2[3]
		if r2x1 >= r1x2 or r1x1 >= r2x2:
			return False
		if r2y1 >= r1y2 or r1y1 >= r2y2:
			return False
		return True


class Solution:

	def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:
		x1 = rec1[0]
		y1 = rec1[1]
		x2 = rec1[2]
		y2 = rec1[3]
		return x1 < rec2[2] and rec2[0] < x2 and (y1 < rec2[3]) and (rec2[1] < y2)


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])


class Solution:

	def isRectangleOverlap(self, r1: List[int], r2: List[int]) -> bool:
		return max(r1[0], r2[0]) < min(r1[2], r2[2]) and max(r1[1], r2[1]) < min(r1[3], r2[3])


class Solution:

	def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:
		(x1, y1, x2, y2) = rec1
		(i1, j1, i2, j2) = rec2
		if i1 >= x2 or x1 >= i2 or y1 >= j2 or (j1 >= y2):
			return False
		return True


class Solution:

	def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:
		sortedR1 = rec1
		if rec1[0] > rec1[2]:
			sortedR1[0] = rec1[2]
			sortedR1[2] = rec1[0]
		if rec1[1] > rec1[3]:
			sortedR1[1] = rec1[3]
			sortedR1[3] = rec1[1]
		sortedR2 = rec2
		if rec2[0] > rec2[2]:
			sortedR2[0] = rec2[2]
			sortedR2[2] = rec2[0]
		if rec2[1] > rec2[3]:
			sortedR2[1] = rec2[3]
			sortedR2[3] = rec2[1]
		if sortedR2[0] < sortedR1[2] and sortedR2[2] > sortedR1[0]:
			if sortedR2[1] < sortedR1[3] and sortedR2[3] > sortedR1[1]:
				return True
		return False


class Solution:

	def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:
		(x1, y1, x2, y2) = rec1
		(x3, y3, x4, y4) = rec2
		return not (x2 <= x3 or x4 <= x1 or y2 <= y3 or (y4 <= y1))