def k_means(points, k, max_iters=100):
Two first-hand phone-screen reports. In one, on the company's own coding pad, there were two clustering-themed problems and both had to be finished. The first: given a 2D array whose elements are points [row, col] and an integer k, split the points into k clusters. The initial centroids can be the first k points; update each cluster's centroid round by round, and return the clustered coordinates. The other report, from an MLE phone screen, says the round was hand-written k-means, with a lot of weight on simplifying and speeding it up with numpy broadcasting.
Part 1 — K-means on grid points
Write k_means(points, k, max_iters=100).
k points as the centroids.max_iters rounds.k lists of points. Cluster j is the one whose centroid started at points[j]; each list keeps the input order.numpy is available. The function name, the return shape and the stopping rule are our setup; the tests avoid points that are equally close to two centroids, and clusters that end up empty.
Two Waymo phone-screen reports. One (a self-driving team phone screen on the company's own coding pad) had two clustering-themed problems, both to be finished: this one, and grouping the [row, col] positions of each character in a multiline string. The other, an MLE phone screen, was hand-written k-means with a lot of weight on numpy broadcasting to simplify and speed it up. Neither report gives the outcome or any follow-up questions.
Two first-hand phone-screen reports. In one, on the company's own coding pad, there were two clustering-themed problems and both had to be finished. The first: given a 2D array whose elements are points [row, col] and an integer k, split the points into k clusters. The initial centroids can be the first k points; update each cluster's centroid round by round, and return the clustered coordinates. The other report, from an MLE phone screen, says the round was hand-written k-means, with a lot of weight on simplifying and speeding it up with numpy broadcasting.
Part 1 — K-means on grid points
Write k_means(points, k, max_iters=100).
k points as the centroids.max_iters rounds.k lists of points. Cluster j is the one whose centroid started at points[j]; each list keeps the input order.numpy is available. The function name, the return shape and the stopping rule are our setup; the tests avoid points that are equally close to two centroids, and clusters that end up empty.
| Approach | Notes |
|---|---|
| Pure Python (no numpy) | Same result and easier to reason about, but slower; one report says the interviewer put a lot of weight on numpy broadcasting. |
| Random or k-means++ initialization | Usually converges to better clusters, but the result changes between runs; one report gives the first k points as the starting centroids. |
Interviewer hints: One MLE phone-screen report says the round put a lot of weight on simplifying and speeding up the code with numpy broadcasting.; In one report the screen had two clustering-themed problems and both had to be finished; the second groups the [row, col] positions of each character in a multiline string.
If you have had this round, tell us how close this page was. It is how we keep the pages accurate.