← Questions
Line reflection symmetry with duplicate points
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Nuro's technical phone screen, last asked Feb 2026. It tests hashing and geometry.
Given points in the plane, possibly with duplicates, decide whether some vertical line reflects the set onto itself. Duplicates count: every occurrence of a point needs a matching occurrence of its reflection.
Interface
Unless you agree on a different interface with the interviewer, assume:
has_vertical_symmetry(points: list[list[int]]) -> bool- The line is
x = c, wherecmay be a half-integer;(x, y)reflects to(2c - x, y). Points on the line reflect to themselves. The empty set is symmetric.
Example
has_vertical_symmetry([[1, 2], [3, 2], [2, 4]]) -> True # x = 2
has_vertical_symmetry([[0, 1], [1, 1]]) -> True # x = 0.5
has_vertical_symmetry([[0, 0], [0, 0], [2, 0]]) -> False # (0, 0) twice, (2, 0) once
has_vertical_symmetry([[1, 1], [-1, 1], [1, 1], [-1, 1]]) -> True # x = 0, counts match
has_vertical_symmetry([]) -> True
Constraints
0 <= len(points) <= 2 · 10^5- Coordinates are integers in
[-10^9, 10^9];2c - xcan exceed 32 bits.
Clarifying questions
- Do duplicate points count separately?
- Can the line fall between integer coordinates?
- What should an empty input return?
What a strong answer covers
- The only possible line is halfway between the smallest and the largest
x, sos = min_x + max_xis fixed; working with2c = skeeps everything in integers. - Counting points in a hash map and checking that each
(x, y)and(s - x, y)have the same count; O(n) time and space. - Points on the line pair with themselves.
- A sorting alternative: group by
y, sort thexvalues and check pairs from both ends. - Tests with the examples, all points on one vertical line, and large coordinates.
Follow-ups
- Check for a horizontal line as well, or for any line.
- Ignore duplicates (treat the points as a set). What changes?
- Find the line that makes the most points symmetric when no perfect line exists.
Where it's asked
- Nuro · Technical phone screen · Last asked Feb 2026
What it tests
hashing · geometry
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
