k-means assignment
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.
0:00 of about 22 min
solution.py
InputExpectedGot
[[[0,0],[10,10]],[[0,0],[10,10]]][0,1]not run yetsample