K-Means Clustering from Scratch
Asked at Apple · Coding Questions · Difficulty: Medium · Last asked Mar 25, 2026
Implement K-Means clustering (Lloyd's algorithm) from scratch using only the Python standard library. Given a set of points, group them into `k` clusters by alternately assigning every point to its nearest centroid and moving every centroid to the mean of the points assigned to it.
Loading the problem…
More Apple interview questions
- LLM conceptual questions
- Implement a Two-Hidden-Layer MLP with Backpropagation in NumPy
- Compare PPO, DPO, and GRPO
- Implement a Vision Transformer (ViT) from Scratch
- Sample from a Gaussian Distribution Using Only Uniform Sampling
- ML Fundamentals and Model Debugging Rapid-Fire