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
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
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code