Reported August 2024
Snowflakegeometry

Closest Squared Distance

Reported by candidates from Snowflake's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Snowflake OA. Under 2s to a working solution.
Founder's read

Snowflake hit you with Closest Squared Distance in August 2024, and you've got 24-48 hours to lock in the pattern. This is a geometry problem wrapped in coordinate math, not a data structure trick. The trap: candidates spend time on optimization when the core insight is just finding the minimum Euclidean distance squared between two points or sets of points. StealthCoder can spot the setup and feed you the formula when you're under live pressure.

Pattern and pitfall

The problem asks you to compute squared distances (to avoid floating point mess) and find the minimum. If you're comparing two points, it's trivial: (x1-x2)^2 + (y1-y2)^2. If you're working with multiple points, you're either brute-forcing all pairs (O(n^2)) or using a spatial divide-and-conquer (O(n log n)) if the input is large. Most candidates overthink and reach for KD-trees. Don't. Start with brute force, verify it works, then optimize only if the time limit screams. Snowflake's assessment likely expects you to recognize that squared distance is symmetric and that you can prune comparisons by sorting. StealthCoder as your live safety net means you won't blank on the distance formula or miss an edge case under pressure.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Closest Squared Distance 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 StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Snowflake's OA.

Snowflake 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.

Closest Squared Distance FAQ

Why squared distance instead of regular distance?+

Avoids square root computation and floating point precision errors. Since sqrt is monotonic, minimizing x^2 is the same as minimizing sqrt(x). It's faster and cleaner in code. The problem statement will hint at this or just use squared distance directly.

Do I need a fancy spatial data structure?+

Not for most inputs. Brute force all pairs in O(n^2) first. If n is under 10,000 and time limit is reasonable, you're done. Only attempt divide-and-conquer or sorting-based pruning if the naive solution times out or the problem explicitly signals large n.

What's the divide-and-conquer trick for closest pair?+

Sort points by x-coordinate. Recursively find the closest pair in left and right halves. Then check a vertical strip in the middle where points could be closer. Merge results. It's O(n log n), but only code it if brute force fails and you're confident.

How do I avoid off-by-one errors with point indices?+

If comparing all pairs, use nested loops: i from 0 to n-1, j from i+1 to n-1. Skip i==j. Track the minimum as you go. Be explicit about whether you're using 0-indexing or 1-indexing; mirror the problem statement exactly.

Is this still asked in 2024 at big companies?+

Yes. Geometry and coordinate problems are standard. They're not trendy, but they're reliable filters. Snowflake asking it in August confirms it's still live. Expect similar problems at other cloud/data companies.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Snowflake.

OA at Snowflake?
Invisible during screen share
Get it