FDEInterviews logo
Coding & DSA / 69
mediumAmazonAppleMeta

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.

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.

20 answers per topic instead of 10, plus saved progress and bookmarks · no cardor unlock all 528 remaining answers · ₹2,000 / $25
UP NEXT ON YOUR JOURNEY
FEDITOR'S NOTE

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.

DISCUSSION · 0

No comments yet — be the first to share your approach.