Imagine you're Alice and you want to build a private rectangular fence around just you and your friend Bob on a 2D plane! ๐
You're given n points where people must be placed, with exactly one person per point. Alice wants to build a rectangular fence where:
- Alice's position is the upper-left corner
- Bob's position is the lower-right corner
- No other people are inside or on the fence boundary
The fence can be a line (zero area) if Alice and Bob share the same x or y coordinate.
Goal: Count how many valid pairs of positions (Alice, Bob) exist where Alice won't be sad due to unwanted visitors in their private space.
Note: "Upper-left" means Alice's x โค Bob's x and Alice's y โฅ Bob's y (remember y-axis increases upward).
Input & Output
Visualization
Time & Space Complexity
O(nยฒ) pairs to check ร O(n) points to verify for each pair
Only using constant extra space for variables
Constraints
-
2 โค
points.lengthโค 50 -
points[i].length == 2 -
-109 โค
xi,yiโค 109 - All points have unique coordinates