Ctrl K

Vertical Mirror Line

Medium
You get points dots on a plane, each given as a pair [x, y]. Some points may coincide. Decide whether there is a vertical line (parallel to the Y axis) that the set of points is symmetric about: reflecting every point across that line gives back exactly the same set of points. Return True if such a line exists and False otherwise. Try to do better than comparing every pair of points.
Example 1
dots=[[2, 5], [6, 5], [4, 1]] → True

Take the line x = 4: (2, 5) and (6, 5) swap places, and (4, 1) lies on the line itself.

Example 2
dots=[[0, 0], [2, 1]] → False

The points are at different heights, so no vertical line can map one onto the other.

Example 3
dots=[[3, 7], [3, 7], [1, 2], [5, 2]] → True

Repeated points are fine: the line x = 3 works.

Constraints
  • 1 ≤ len(dots) ≤ 10⁵
  • -10⁸ ≤ x, y ≤ 10⁸
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsEquidistant Point Triples MediumA Stretch Divisible by k MediumFewest Guests by Lanyard Color MediumMagic 3×3 Blocks MediumSmallest Paddock Medium
loading Python…
Input
dots=[[2, 5], [6, 5], [4, 1]]
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 141 tests on the server, hidden ones included.