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

Deterministic K-Means Assignments

Google logoGoogle● HardFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Based on a Google ML interview report that asked for a k-means implementation. The report does not say how to start, how to break distance ties, what to do with empty clusters, or when to stop. Here we state fixed choices for each. Our version is about 40% the same as the reported question.

Implement deterministic K-Means clustering for integer points. 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 Google Phone Screen questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
  • Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Deterministic K-Means AssignmentsLyft · PHONE SCREENLyft interview questions
  • Online Chess Move ValidationOpenAI · PHONE SCREENOpenAI interview questions
  • Deterministic K-Means AssignmentsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta 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

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[] clusterPoints(int[][] points, int k) {
        // write your code here
    }
}
Checking account…