Skip to content

Commit bb5061e

Browse files
committed
daily
1 parent 3ffdab3 commit bb5061e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

my-submissions/m3025.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Points sorted by $x$ then $-y$ since minimizing $x$ gives us the "leftmost" points and $-y$ gives us a secondary sorting based on the largest $y$ values. This lets us iterate and only check points right of a point in the list since any others are either left or above meaning the pairing has already been checked.
2+
3+
Since the points are sorted in such a manner, when comparing two points the only points that could be "between" are those between the two in the points[] array since values that are between $x$-wise will be sorted between them first and $y$-wise as a secondary case.

my-submissions/m3025.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def numberOfPairs(self, points: List[List[int]]) -> int:
3+
points.sort(key=lambda x: (x[0], -x[1]))
4+
5+
output = 0
6+
# Top left
7+
for i, (x1, y1) in enumerate(points) :
8+
# top right
9+
for j, (x2, y2) in enumerate(points[i + 1:], i + 1) :
10+
# valid pair
11+
if x2 < x1 or y2 > y1 :
12+
continue
13+
# Check for "between" points
14+
if all(not (x1 <= x3 <= x2 and y2 <= y3 <= y1) for x3, y3 in points[i + 1:j]) :
15+
output += 1
16+
17+
return output

0 commit comments

Comments
 (0)