I consider a pair of points
class Solution:
def numberOfPairs(self, points: List[List[int]]) -> int:
n = len(points)
ans = 0
for i in range(n):
xi, yi = points[i]
for j in range(n):
if i == j:
continue
xj, yj = points[j]
if xi <= xj and yi >= yj:
empty = True
for k in range(n):
if k == i or k == j:
continue
xk, yk = points[k]
if xi <= xk <= xj and yj <= yk <= yi:
empty = False
break
if empty:
ans += 1
return ans
- Time: O(n^2)
- Space: O(1)
