spots, where spots[i] = [x, y]. The x axis points right and the y axis points up. All spots are distinct, and each will hold exactly one tent.
Two friends want to pick spots A and B and fence off an axis-aligned rectangle with A as its upper-left corner and B as its lower-right corner, so A.x ≤ B.x and A.y ≥ B.y. The rectangle may collapse into a segment.
A pair works if no other tent stands inside the rectangle or on its border. Return the number of ordered pairs (A, B) that work.spots=[[0, 4], [2, 2], [4, 0]] → 2
The pairs (0, 4) → (2, 2) and (2, 2) → (4, 0) work. The pair (0, 4) → (4, 0) does not: (2, 2) is inside its rectangle.
spots=[[1, 1], [1, 3], [3, 3]] → 2
(1, 3) → (1, 1) is a vertical segment and (1, 3) → (3, 3) a horizontal one, both empty. No other pair has its first point up and to the left of the second.
spots=[[0, 0], [5, 5]] → 0
(0, 0) is to the left of (5, 5) but below it, so neither order makes a valid upper-left corner.
spots=[[0, 4], [2, 2], [4, 0]]
2
Run checks the first 3 tests in your browser. Submit checks all 121 tests on the server, hidden ones included.