Minimum Euclidean Distance Between Points
Reported by candidates from Luma AI's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Luma AI reported this one in June 2026, and the example is small: three points, closest pair is (-7,1) and (-5,-3), answer 4.47213595499958. Don't let that fool you. It's the classic closest pair of points problem, with up to 20000 points. If your OA invite is sitting in your inbox, this is the one where brute force looks tempting and quietly fails. Coordinates go up to 10^7 and the checker accepts 1e-5 tolerance. StealthCoder is the safety net if you blank on the divide and conquer during the live OA, but the idea is learnable in an evening.
The problem
Given Cartesian points in points, return the minimum Euclidean distance between two entries with different indices. Function minimumEuclideanDistance(points: int[][]) → double Examples Example 1 points = [[0,11],[-7,1],[-5,-3]] return = 4.47213595499958 The closest pair is (-7,1) and (-5,-3). Constraints 2 <= points.length <= 20000. points[i].length == 2. |points[i][j]| <= 10^7. Results use absolute tolerance 1e-5.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is divide and conquer. Sort points by x, split in half, solve each side recursively, and take d as the smaller of the two results. Then check only points within d of the middle vertical line, sorted by y. Each of those only needs comparison with the next several points in y order, so the merge is linear and the total is O(n log n). The pitfall is the n squared brute force. With 20000 points that's about 200 million pair checks, which may pass or may time out, so don't bet on it. Another pitfall is square roots and precision. Compare squared distances as integers in a 64-bit type, and take one sqrt at the end. Squared differences reach about 4*10^14, so int overflow is a real risk. If the recursion shape escapes you mid-assessment, StealthCoder can hand you a working version while you keep your composure.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Minimum Euclidean Distance Between Points cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Luma AI's OA.
Luma AI reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimum Euclidean Distance Between Points FAQ
How hard is Minimum Euclidean Distance really?+
It's a known hard-ish problem, closest pair of points. The statement is easy to read, but the efficient solution needs divide and conquer or a grid approach. With n up to 20000, a brute force O(n^2) is borderline, so plan for O(n log n).
What's the trick to solving it fast?+
Sort by x, split, recurse, then scan the strip near the dividing line. Only points within d of the midline matter, and in y order each needs just a handful of neighbors checked. That keeps the merge step linear instead of quadratic.
Can I just use brute force?+
Maybe, since 20000 points means roughly 200 million pair checks. Some judges let it through in a fast language, others don't. Don't rely on it. Write brute force first as a fallback and a correctness check, then upgrade to divide and conquer if you have time.
How do I avoid precision and overflow bugs?+
Work with squared distances in 64-bit integers. Coordinates reach 10^7, so a difference can hit 2*10^7 and its square 4*10^14, which overflows 32-bit. Take the square root only once at the end. The 1e-5 tolerance makes a double return fine.
How do I prepare in 48 hours?+
Code closest pair from scratch twice. Once with brute force, once with divide and conquer and the strip check. Test with duplicate points (distance 0), all points on a line, and the two-point minimum case. Those edge cases are where most wrong answers come from.