Implement a clustering algorithm (some helper methods could be assumed to be implemented). Asked in the ML Coding stage. Loop round for Sr Delivery Consultant GenAI/ML; the interviewer did not require perfectly executing code.
Implement k_means(points, k, max_iterations). points is a non-empty list of equal-length numeric lists. Initialize centroids from the first k points, assign each point to its nearest centroid using squared Euclidean distance, and recompute each centroid as the coordinate-wise mean. Break when centroids stop changing or after max_iterations. If initial centroids contain duplicates, return them unchanged. Return a list of centroid lists in centroid-index order. Ties choose the lowest index.
def k_means(points, k, max_iterations):