Symmetric Coordinates - Problem
Given a table of coordinate points, find all symmetric coordinate pairs that exist in the table.
Two coordinates (X1, Y1) and (X2, Y2) are considered symmetric if:
X1 == Y2andX2 == Y1
From all symmetric pairs found, return only the unique coordinates where X โค Y, ordered by X and Y in ascending order.
Example: Points (1, 2) and (2, 1) are symmetric because the X-coordinate of the first equals the Y-coordinate of the second, and vice versa.
This problem tests your ability to identify coordinate relationships and apply filtering conditions efficiently.
Input & Output
example_1.py โ Basic Symmetric Pairs
$
Input:
coordinates = [[1,2],[2,1],[3,4],[4,3],[5,5]]
โบ
Output:
[[1,2],[3,4],[5,5]]
๐ก Note:
(1,2) and (2,1) are symmetric, (3,4) and (4,3) are symmetric, (5,5) is symmetric with itself. All satisfy X โค Y condition.
example_2.py โ No Symmetric Pairs
$
Input:
coordinates = [[1,2],[3,4],[5,6]]
โบ
Output:
[]
๐ก Note:
No symmetric pairs exist - none of these coordinates have their mirror coordinates in the table.
example_3.py โ Duplicate Coordinates
$
Input:
coordinates = [[1,2],[2,1],[1,2],[2,1],[0,0]]
โบ
Output:
[[0,0],[1,2]]
๐ก Note:
Even with duplicates, we return unique coordinates. (0,0) is symmetric with itself, and (1,2)/(2,1) form a symmetric pair.
Constraints
- 1 โค coordinates.length โค 1000
- -106 โค X, Y โค 106
- coordinates may contain duplicate entries
- Result must be sorted by X coordinate first, then Y coordinate
Visualization
Tap to expand
Understanding the Visualization
1
Identify Pattern
Two points (a,b) and (c,d) are symmetric if a=d and b=c
2
Hash Table Storage
Store each coordinate as we see it and look for its mirror
3
Apply Filters
Only keep unique results where X โค Y to avoid duplicates
4
Sort Results
Return coordinates ordered by X, then Y
Key Takeaway
๐ฏ Key Insight: Use hash table lookups to find symmetric partners in O(1) time instead of checking all pairs
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code