Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

its not a nearest neighbor problem that is incorrect, they expect candidates to have the heap solution on the first go, you have 10-15 minutes to answer, no time to optimize, cheaters get blacklisted, welcome to the new reality


Finding the k points closest to the origin (or any other point) is obviously the k-nearest neighbors problem. What algorithm and data structure you use does not change that.

https://en.wikipedia.org/wiki/Nearest_neighbor_search

edit: If you want to use a heap, the general solution is to define an appropriate cost function; e.g., the p-norm distance to a reference point. Use a union type with the distance (for the heap's comparisons) and the point itself.


true, I am thinking, Node and neighbors, this is a heap problem, it actually does matter what algorithm you use, I learn that the hard way today, trying to implement quickselect vs using a heap library (I didn't know you could do that) is much easier, don't make the same mistake!


Wish it was more how you think than requiring boolean correct/incorrect answer on the whiteboard after 15min.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: