LeetCode Entry
836. Rectangle Overlap
Rectangle overlap?
836. Rectangle Overlap easy substack youtube
https://dmitrysamoylenko.com/leetcode/

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/1482
Problem TLDR
Rectangle overlap?
Intuition
20 minutes for this easy problem.
//
// xxxxxxx 12,20
// x x
// x*****x****13,15
// x x *
// x x *
// x x *
// xxxxxxx******
// 7,8 10,8
//
//
Left side of intersection is max(La,Lb). Right side of intersection is min(Ra,Rb). Same for the Y coordinate.
Approach
- max(La,Lb)<min(Ra,Rb) is simplified to La < Rb && Lb < Ra
Complexity
-
Time complexity: \(O(1)\)
-
Space complexity: \(O(1)\)
Code
fun isRectangleOverlap(a: IntArray, b: IntArray) =
(0..1).all{i->a[i]<b[i+2]&&b[i]<a[i+2]}
pub fn is_rectangle_overlap(a: Vec<i32>, b: Vec<i32>) -> bool {
(0..2).all(|i|a[i]<b[i+2]&&b[i]<a[i+2])
}
Comments