Deterministic K-Means Assignments
Reported by candidates from Meta's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Meta reported this one in September 2026, and the title sounds scarier than it is. It's a deterministic K-Means simulation: first k points seed the centroids, assign, recompute, repeat until nothing moves. No clustering library allowed, so you write the loop yourself. If you've got an OA invite and 48 hours, this is about careful implementation, not a clever algorithm. The tie-break and the empty-cluster rule are where people lose points. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the logic below is short enough to carry in your head.
The problem
Implement deterministic K-Means clustering for integer points. Use the first k points as the initial centroids, in that order. Repeat these steps until no point changes its assigned cluster: Assign every point to the centroid with the smallest squared Euclidean distance. Break a tie by choosing the smaller cluster index. Replace each nonempty cluster's centroid with the coordinate-wise arithmetic mean of its assigned points. If a cluster is empty, keep its previous centroid. Return an integer array whose value at index i is the zero-based cluster index assigned to points[i]. Implement the arithmetic and iteration directly; do not call a clustering library. Function clusterPoints(points: int[][], k: int) → int[] Examples Example 1 points = [[0,0],[10,10],[1,0],[9,10]] k = 2 return = [0,1,0,1] The first two points initialize the two centroids. The two points near the origin join cluster 0, and the two points near [10,10] join cluster 1. Recomputed centroids preserve those assignments. Example 2 points = [[0],[4],[2]] k = 2 return = [0,1,0] The point [2] is initially equally distant from centroids 0 and 4, so the smaller cluster index wins the tie. Example 3 points = [[-5,2],[7,-1],[3,4]] k = 3 return = [0,1,2] When every point initializes its own cluster, each point remains at distance zero from that centroid. Constraints 1 <= points.length <= 200 1 <= points[i].length <= 10 All points have the same dimension. 1 <= k <= min(points.length, 10) The first k points are pairwise distinct. -10000 <= points[i][j] <= 10000
Reported by candidates. Source: FastPrep
Pattern and pitfall
Look at the constraints first. At most 200 points, 10 dimensions, k up to 10. One iteration costs about 200 x 10 x 10 = 20,000 operations, so brute force per iteration is fine. You don't need a spatial index or anything fancy. The pattern is plain simulation over arrays. The traps are all in the details. Use squared distance, never a square root. Break ties with a strict less-than while scanning clusters from index 0, so the smaller index wins. Keep the old centroid when a cluster is empty. Centroid means can be fractional, so store them as doubles, not ints, or integer division will change your assignments. Stop when the assignment array is identical to the previous one. Initialize the previous assignment to something like -1 so the first pass always counts as a change. If you freeze on the mean math during the live OA, StealthCoder is the hedge that gets you a working loop fast.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Deterministic K-Means Assignments cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Meta's OA.
Meta reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Deterministic K-Means Assignments FAQ
How hard is Deterministic K-Means Assignments really?+
Easy to medium. There's no hidden algorithm, just a simulation with small inputs. Most failures come from the tie-break, empty clusters, or integer division on centroids. If you code it cleanly and test the three examples, you're in good shape.
What's the trick to getting it right?+
Treat the rules as literal code. Scan clusters in index order and update the best only on strictly smaller distance. Store centroids as doubles. Skip updates for empty clusters. Loop until the assignment array stops changing.
Will brute force time out here?+
No. With 200 points, 10 dimensions and k up to 10, each iteration is roughly 20,000 operations. Even many iterations are cheap. Don't optimize distance with square roots or trees. Squared distance is enough and avoids float error.
How do I handle ties and empty clusters?+
For ties, compare with strict less-than while iterating cluster indices upward, so the lowest index stays. For an empty cluster, leave its centroid unchanged and don't divide by zero. Example 2 in the problem checks the tie case directly.
How do I prepare for this in 48 hours?+
Write the full loop once from scratch and run all three examples. Then test edge cases: k equals the number of points, one dimension, negative coordinates, and a cluster that ends up empty. That covers nearly every way this question fails.