EASYasked at 1 company

Find Nearest Point That Has the Same X or Y Coordinate

A easy-tier problem at 69% community acceptance, tagged with Array. Reported in interviews at DoorDash and 0 others.

Founder's read

DoorDash asks this problem at an acceptance rate near 69 percent, which means it's both common and beatable. You're given a list of points and a point P; find the one closest to P that shares an X or Y coordinate. It looks trivial on the surface, scan the array, compare distances, return the minimum. The trap is handling ties and edge cases without overthinking it. Most candidates solve this cleanly in under five minutes. If you blank on the comparison logic during the live OA, StealthCoder runs invisibly and surfaces a working solution in seconds.

Companies asking
1
Difficulty
EASY
Acceptance
69%

Companies that ask "Find Nearest Point That Has the Same X or Y Coordinate"

If this hits your live OA

Find Nearest Point That Has the Same X or Y Coordinate is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop.

Get StealthCoder
What this means

The algorithmic pattern is straightforward: iterate through all points, filter those that match P's X or Y coordinate, calculate Manhattan distance for each, and return the one with minimum distance. The gotcha is tie-breaking, when two points are equidistant, you must return by index order. Candidates often miss this nuance or add unnecessary complexity with sorting. The obvious O(n) scan with a single pass works perfectly. Because the constraint is just matching one coordinate (not both), you'll never have a point equal to P itself unless it's explicitly in the input. This is an Array fundamentals problem disguised as geometry. If you drill the basic filter-and-compare pattern, it's automatic. StealthCoder handles it instantly if the logic slips during your live assessment.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Find Nearest Point That Has the Same X or Y Coordinate recycles across companies for a reason. It's easy-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Find Nearest Point That Has the Same X or Y Coordinate interview FAQ

Is this problem actually easy?+

Yes. Nearly 70 percent acceptance rate confirms it. The logic is a single pass through the array with basic distance comparison. The only trick is remembering to return the first matching point by index when distances tie, which most candidates catch in a second read of the problem.

What's the difference between Euclidean and Manhattan distance here?+

The problem asks for the closest point, and closest typically means Euclidean (sqrt of sum of squared differences). However, since you're only comparing distances, you can skip the sqrt and compare squared distances to avoid floating-point errors. Either works if applied consistently.

Do I need to sort or use a data structure?+

No. A single pass with a running minimum distance is enough. Sorting or using a heap adds complexity and kills time. Iterate once, track the closest point seen so far, return it. O(n) time, O(1) space.

How does this relate to interview difficulty at DoorDash?+

DoorDash has asked this at easy difficulty, which means it's a warm-up or filtering question. If you see it in your OA, it's a gift. Solve it cleanly and move on. Missing it signals careless reading or implementation bugs, not lack of skill.

What happens if no point shares a coordinate with P?+

The problem guarantees at least one point matches. If your input has no matches, the problem is malformed. Handle it by returning -1 or null as a safety measure, but the test cases won't trigger it. Read the constraints carefully before coding.

Want the actual problem statement? View "Find Nearest Point That Has the Same X or Y Coordinate" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.