Lyft

Verified interview challenge

Implement K-means centroid updates

Implement the assignment and centroid-update steps of K-means with deterministic edge-case behaviour.

Unlock with Full Access

The challenge

The dataset, starting centroids and iteration count are supplied. Run the required rounds while keeping point assignment separate from updating the centroids for the next round. The full task defines how ties and empty clusters behave, so results must follow those rules consistently rather than depend on incidental iteration order.

What you'll practise

  • Iteration state

    Use a consistent centroid snapshot for each assignment round.

  • Numerical behaviour

    Preserve deterministic cluster selection and coordinate updates across edge cases.

Your coding workspacePreview
solution.pyPython 3.13
# Your implementation goes here

# Run examples and inspect results

# Full starter code included
Test cases

Run your code to see results.

Full instructions, starter code and test cases included with Full Access.