There is no training, just storage; the work is at query time. The signal is whether you vectorize the distance computation, break ties sensibly, and know when O(n) per query forces you onto an ANN index instead.
Implement a k-nearest-neighbors classifier from scratch.
There is no training, just storage; the work is at query time. The signal is whether you vectorize the distance computation, break ties sensibly, and know when O(n) per query forces you onto an ANN index instead.
Updated Aug 2026 · Grounded in real Forward Deployed Engineer interview loops and written to a senior-engineer editorial bar.
k-NN is the easiest model to state and the easiest to get subtly wrong. Interviewers watch for the tie-break (even k with a split vote), distance-weighting, and whether you mention that this is O(n*d) per query with zero training, which is the exact tradeoff that makes it useless at scale without an approximate index. Quote 'lazy learner' and explain what lazy buys and costs you.
No comments yet — be the first to share your approach.
