Given n points on a 2D plane, determine whether there is a line parallel to the y-axis that reflects the given set of points symmetrically.
In other words, decide whether some vertical line exists such that reflecting every point over it produces exactly the original set of points. A point (x, y) reflected over the vertical line x = k becomes (2k - x, y).
Function Signature
def is_reflected(points: list[list[int]]) -> bool:
Rules
-
Each point is given as
[x, y]
.
-
Points are compared as a set. If the same point appears more than once, the copies count as one point, so a repeated point does not need a repeated mirror.
-
The line
x = k
may sit at any real
k
, including a half-integer such as
x = 0.5
.
-
A point that lies on the line is its own reflection.
-
Return
True
if such a line exists, otherwise
False
.
Constraints
-
n == len(points)
-
1 <= n <= 10^4
-
-10^8 <= points[i][j] <= 10^8
Examples
Input: points = [[1, 1], [-1, 1]]
Output: True
The line x = 0 maps (1, 1) to (-1, 1) and back, so every point has its mirror in the set.
Input: points = [[1, 1], [-1, -1]]
Output: False
A vertical reflection keeps the y-coordinate, and the two points have different y values, so each point would have to be its own mirror. That needs both points on the line, but their x-coordinates differ.
Input: points = [[1, 1], [1, 1], [-1, 1], [0, 5]]
Output: True
With the line x = 0, the points (1, 1) and (-1, 1) mirror each other and (0, 5) lies on the line. The repeated (1, 1) counts once.