Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Create a function to perform k-means clustering on a dataset and return the cluster centers.

Hard

Problem Statement

Create a function to perform k-means clustering on a dataset and return the cluster centers.

Sample Input

Data: 
 x y
1 1 2
2 2 3
3 3 4
4 8 7
5 9 8
6 10 9

Sample Output

Cluster Centers:
  x y
1 9 8
2 2 3

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
# Predefined structure perform_kmeans <- function(df, k) { # Your logic here } # Call the function
Log in or sign up to run or submit your code.Log inSign up
Input
Data: 
 x y
1 1 2
2 2 3
3 3 4
4 8 7
5 9 8
6 10 9
Expected Output
Cluster Centers:
  x y
1 9 8
2 2 3