Rectangle Overlap
Real-world version: Do the Two Plots Share Any GroundThe statement here is our own: the same inputs, outputs and technique.
A plot is given as [x1, y1, x2, y2]: the coordinates of its bottom-left corner followed by those of its top-right corner, with its sides parallel to the axes. Both plots enclose a positive area.
Two plots share ground when the region they have in common encloses a positive area. Merely touching along an edge or at a corner does not count.
Return whether plot1 and plot2 share ground.
Examples
Example 1
- Input
- plot1 = [0, 0, 5, 5], plot2 = [1, 1, 2, 2]
- Output
- true
The second plot sits wholly inside the first, so the region they share is the whole of the second plot.
Example 2
- Input
- plot1 = [0, 0, 1, 1], plot2 = [0, 1, 1, 2]
- Output
- false
The two plots meet along a horizontal edge but neither reaches into the other, so the region they share is a line with no area.
Example 3
- Input
- plot1 = [0, 0, 3, 1], plot2 = [1, 2, 2, 5]
- Output
- false
Their horizontal spans do overlap, but the first plot stops at height one and the second starts at height two, so there is no vertical overlap at all.
Constraints
- plot1.length == 4
- plot2.length == 4
- -10^9 <= plot1[i] <= 10^9
- -10^9 <= plot2[i] <= 10^9
- Each plot encloses a positive area.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def is_rectangle_overlap(plot1: list[int], plot2: list[int]) -> bool:public boolean isRectangleOverlap(int[] plot1, int[] plot2)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's