68Implement k-means clustering from scratch.▼medium★ EssentialMetaGoogleAmazon1 replies◆ premiumThe assign-then-update loop is ten lines; the signal is whether you handle the three things that bite in production: initialization, an empty cluster, and a real convergence test instead of a fixed iteration count.Open full answer →
69Implement a k-nearest-neighbors classifier from scratch.▼mediumAmazonAppleMeta2 replies◆ premiumThere 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.Open full answer →
70Implement scaled dot-product attention (the forward pass).▼hardOpenAIAnthropicGoogle2 replies◆ premiumsoftmax(QKᵀ/√d_k)·V in four lines, but the grade is the three details people drop: the √d_k scale, subtracting the row max for numerical stability, and getting the causal mask to add -inf before the softmax, not after.Open full answer →
71Compute the dot product of two sparse vectors.▼mediumMetaGoogle1 replies◆ premiumThe whole question is the representation: store only the nonzeros as index→value, then either two-pointer over sorted indices or hash-join. The follow-up that decides the design is what happens when one vector is dense.Open full answer →