Find the Number of Ways to Place People II
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].
We define the right direction as the positive x-axis (increasing x-coordinate) and the left direction as the negative x-axis (decreasing x-coordinate). Similarly, we define the up direction as the positive y-axis (increasing y-coordinate) and the down direction as the negative y-axis (decreasing y-coordinate).
You have to place n people, including Alice and Bob, at these points such that there is exactly one person at every point. Alice wants to be alone with Bob, so Alice will build a rectangular fence with Alice's position as the upper left corner and Bob's position as the lower right corner of the fence. Note that the fence might not enclose any area; it can be a line. If any person other than Alice and Bob is either inside the fence or on the fence, Alice will be sad.
Return the number of pairs of points where you can place Alice and Bob such that Alice does not become sad after building the fence.
Note that Alice can only build a fence with Alice's position as the upper left corner and Bob's position as the lower right corner. For example, Alice cannot build either of the fences with four corners (1, 1), (1, 3), (3, 1), and (3, 3) in these cases:
- With Alice at
(3, 3)and Bob at(1, 1), Alice's position is not the upper left corner and Bob's position is not the lower right corner of the fence. - With Alice at
(1, 3)and Bob at(1, 1)as a rectangle instead of a line, Bob's position is not the lower right corner of the fence.
points = [[1,1],[2,2],[3,3]]0points = [[6,2],[4,4],[2,6]]2Constraints
- 2 <= n <= 1000
- points[i].length == 2
- -10^9 <= points[i][0], points[i][1] <= 10^9
- All points[i] are distinct.