Line Reflection - Problem

Given n points on a 2D plane, find if there is such a line parallel to the y-axis that reflects the given points symmetrically.

In other words, answer whether or not if there exists a line that after reflecting all points over the given line, the original points' set is the same as the reflected ones.

Note: There can be repeated points.

Input & Output

Example 1 — Perfect Symmetry
$ Input: points = [[1,1],[-1,1]]
Output: true
💡 Note: The reflection line is at x = 0. Point (1,1) reflects to (-1,1) and vice versa. Both reflections exist in the original set.
Example 2 — No Symmetry
$ Input: points = [[1,1],[-1,-1]]
Output: false
💡 Note: The reflection line would be at x = 0. Point (1,1) reflects to (-1,1), but (-1,1) doesn't exist. Point (-1,-1) reflects to (1,-1), but (1,-1) doesn't exist.
Example 3 — Single Point
$ Input: points = [[0,0]]
Output: true
💡 Note: A single point can always be reflected across a line through itself, so it's symmetric.

Constraints

  • 1 ≤ points.length ≤ 104
  • -108 ≤ points[i][0], points[i][1] ≤ 108

Visualization

Tap to expand
Line Reflection: Find Vertical Mirror LineInput Points(1,3)(2,3)(3,4)(4,4)After Reflection(4,3)(3,3)(2,4)(1,4)Mirror Line x=2.5Check: Do all reflected points exist in original set?Result: true (perfect symmetry found)
Understanding the Visualization
1
Input Points
Given set of 2D points on a plane
2
Find Mirror Line
Calculate center line and test for symmetry
3
Check Reflections
Verify each point has its mirror image
Key Takeaway
🎯 Key Insight: The reflection line must be at the exact center of min and max x-coordinates
Asked in
Google 15 Facebook 12 Amazon 8
28.0K Views
Medium Frequency
~15 min Avg. Time
456 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