Code Room
CodingMediumcod-g977
Subject Ml algorithmsLevel Mid–Senior~22 minCommon in ML systems interviewsIndustries Software development, Technology

Question

Perform a single k-means assignment step. Given a list of data points (each a list of floats) and a list of current centroids (same dimensionality), return a list of integers where the i-th entry is the index of the centroid nearest to point i by squared Euclidean distance. There is at least one centroid. Break ties by choosing the lowest centroid index.

Implement
assign_clusters(points: list[list[float]], centroids: list[list[float]]) → list[int]
Examples
in[[[0,0],[10,10]],[[0,0],[10,10]]]out[0,1]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.