Check whether a set of 2D points has a vertical line of symmetry

Quick Overview

Decide whether a set of 2D points is symmetric about some line parallel to the y-axis, so that reflecting every point over that line gives back the same set. It tests reasoning about where a mirror line can sit and fast lookups on coordinate pairs.

Check whether a set of 2D points has a vertical line of symmetry

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

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 ```python 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 ```text 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. ```text 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. ```text 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.

Overview: Decide whether a set of 2D points is symmetric about some line parallel to the y-axis, so that reflecting every point over that line gives back the same set. It tests reasoning about where a mirror line can sit and fast lookups on coordinate pairs.

Nov 24, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

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.