All problems
1028EasyMathGeometry

Do the Two Plots Share Any Ground

Tracked in this browser only
Write code

Trains the technique from

LeetCode 836Rectangle Overlap

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def is_rectangle_overlap(plot1: list[int], plot2: list[int]) -> bool:
Java
public boolean isRectangleOverlap(int[] plot1, int[] plot2)
September 7
Apply