FDEInterviews logoFDE/Interviews
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.

Unlock the other 466 answers · ₹2,000 / $25Your progress and mastery stay saved · 6 months · one payment · no auto-renew
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.