FastPrepDeterministic K-Means Assignments
Problems/Deterministic K-Means Assignments

Deterministic K-Means Assignments

Lyft logoLyft● HardFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: An earlier interview report asks for K-Means from scratch without NumPy or SciPy. A later report allows NumPy and asks for a K-Means that passes test cases. Here, you write the math and the loop yourself, without calling a clustering library. We chose these. The first k points start the centers. The loop stops when no assignment changes. An empty cluster keeps its old center. Ties go to the smaller index. Assignments start at zero. The limits are finite. Our version is about 72% the same as the reported questions.

Implement K-Means clustering for integer points, with no randomness. Use the first k points as the initial centroids, in that order.

Repeat these steps until no point changes its assigned cluster:

  1. Assign every point to the centroid with the smallest squared Euclidean distance. Break a tie by choosing the smaller cluster index.
  2. Replace each nonempty cluster's centroid with the coordinate-wise arithmetic mean of its assigned points. If a cluster is empty, keep its previous centroid.

Return an integer array whose value at index i is the zero-based cluster index assigned to points[i]. Implement the arithmetic and iteration directly; do not call a clustering library.

Function

clusterPoints(points: int[][], k: int) → int[]

Examples

Example 1

points = [[0,0],[10,10],[1,0],[9,10]]k = 2return = [0,1,0,1]

The first two points initialize the two centroids. The two points near the origin join cluster 0, and the two points near [10,10] join cluster 1. Recomputed centroids preserve those assignments.

Example 2

points = [[0],[4],[2]]k = 2return = [0,1,0]

The point [2] is initially equally distant from centroids 0 and 4, so the smaller cluster index wins the tie.

Example 3

points = [[-5,2],[7,-1],[3,4]]k = 3return = [0,1,2]

When every point initializes its own cluster, each point remains at distance zero from that centroid.

Constraints

  • 1 <= points.length <= 200
  • 1 <= points[i].length <= 10
  • All points have the same dimension.
  • 1 <= k <= min(points.length, 10)
  • The first k points are pairwise distinct.
  • -10000 <= points[i][j] <= 10000

More Lyft interview questions

  • Minimum Window SubstringPHONE SCREEN · Seen Oct 2026
  • Stateful Paginated Fetch NPHONE SCREEN · Seen Sep 2026
  • Reconstruct a BST from PreorderPHONE SCREEN · Seen Aug 2026
  • Validate Binary Search TreePHONE SCREEN · Seen Aug 2026
  • Keyboard Autocomplete SuggestionsONSITE INTERVIEW · Seen Nov 2026
  • Nested Transaction Key-Value Store with Value CountsONSITE INTERVIEW · Seen Sep 2026
  • Globally Versioned Key-Value StoreONSITE INTERVIEW · Seen Sep 2026
  • Rotten Oranges / Grid Infection BFSOA · Seen Aug 2026
  • Minimum Workers with Job AssignmentsONSITE INTERVIEW · Seen Jul 2026

Similar questions at other companies

  • Online Chess Move ValidationOpenAI · PHONE SCREENOpenAI interview questions
  • Deterministic K-Means AssignmentsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Knockout Tournament Win ProbabilityGoogle · PHONE SCREENGoogle interview questions
  • Scaled Dot-Product AttentionAmazon · PHONE SCREEN
  • Deterministic K-Means AssignmentsMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
  • Implement K-Means ClusteringApple · PHONE SCREENApple interview questions
  • Sliding Window Attention over a KV CacheNVIDIA · PHONE SCREENNVIDIA interview questions
  • Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
  • Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
  • Apply Affine Array TransformationsByteDance · PHONE SCREENByteDance interview questions

Lyft interview experiences

  • Lyft MLE Intern Statistics Phone Screen: 1 Experience
All Lyft interview questionsSee Lyft hiring insights
Saved
class Solution {
    public int[] clusterPoints(int[][] points, int k) {
        // write your code here
    }
}
Checking account…