Find the Number of Ways to Place People I - Problem
You are given a 2D array points of size n x 2 representing integer coordinates of some points on a 2D plane, where points[i] = [xi, yi].
Count the number of pairs of points (A, B), where A is on the upper left side of B, and there are no other points in the rectangle (or line) they make (including the border), except for the points A and B.
Return the count.
Input & Output
Example 1 — Basic Rectangle
$
Input:
points = [[1,1],[2,2],[3,3]]
›
Output:
0
💡 Note:
No valid pairs exist. For each pair, either one point is not upper-left of the other, or there are points on the boundary of their rectangle.
Example 2 — Valid Pair
$
Input:
points = [[6,2],[4,4],[2,6]]
›
Output:
2
💡 Note:
Point (2,6) is upper-left of (4,4) and (6,2). Point (4,4) is upper-left of (6,2). All rectangles are empty, so we have 2 valid pairs.
Example 3 — Blocked Rectangle
$
Input:
points = [[0,0],[1,1],[2,0]]
›
Output:
1
💡 Note:
Only (1,1) is upper-left of (2,0) with an empty rectangle between them.
Constraints
- 2 ≤ points.length ≤ 50
- points[i].length == 2
- 0 ≤ xi, yi ≤ 50
- All the given points are unique
Visualization
Tap to expand
Understanding the Visualization
1
Input Points
Given points on 2D plane: [[6,2],[4,4],[2,6]]
2
Find Upper-Left Relations
Check which points can be upper-left of others
3
Verify Empty Rectangles
Count pairs with no points inside their rectangle
Key Takeaway
🎯 Key Insight: A point A is upper-left of B when A.x ≤ B.x and A.y ≥ B.y, with empty rectangle between them
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code