Back to problems

Implement K-Means and Detect Divisible Subarrays

Algorithm · Microsoft · Hard

Part A: K-Means Clustering Edge Cases Invalid k: raise ValueError when k n. Duplicate points: duplicate initial centroids are allowed; ties are resolved toward the smaller centroid index. Empty cluster: its centroid is left unchanged for that iteration. Convergence: stops when every centroid moves by at most tolerance, or when max_iterations is reached. max_iterations = 0: returns the initial centroids and the assignment determined by them. Complexity Time: O(max_iterations…

Checking your access…