The tell is whether you avoid the trap of sorting all n points when you only need k. Two real answers: a max-heap of size k at O(n log k), or quickselect at O(n) average. Knowing which one the interviewer wants is the actual question.
Find the k closest points to the origin
The tell is whether you avoid the trap of sorting all n points when you only need k. Two real answers: a max-heap of size k at O(n log k), or quickselect at O(n) average. Knowing which one the interviewer wants is the actual question.
Updated Aug 2026 · Grounded in real Forward Deployed Engineer interview loops and written to a senior-engineer editorial bar.
The reserved follow-up is 'do we need to sort the full list?', and the answer is no: you need the k closest in any order, not a full ranking, so a total sort at O(n log n) is wasted work. Leading with the size-k heap and then offering quickselect as the O(n)-average alternative, with the conditions under which each wins, is the staff-level signal. Comparing squared distances instead of taking square roots is the small detail that shows you've actually thought about it.
No comments yet — be the first to share your approach.
