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 == Y2 and X2 == 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
Coordinate Symmetry VisualizationXYy = x(1,2)(2,1)Symmetric!(3,3)Self-symmetric
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
Asked in
Google 42 Amazon 35 Meta 28 Microsoft 22
52.4K Views
Medium Frequency
~15 min Avg. Time
1.8K Likes
Ln 1, Col 1
Smart Actions
๐Ÿ’ก Explanation
AI Ready
๐Ÿ’ก Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen