FastPrepK-Means Clustering
Problems/K-Means Clustering

K-Means Clustering

Fortinet logoFortinet● MediumOA

Updated Sep 2026

QuestionFunctionExamples

Problem statement

In a k-means clustering problem, a dataset contains n data points, where i data point is represented by the feature vector location[i]. The goal is to create k clusters. where the cluster centers or the cluster centroids can be placed at any point in the feature space. The overall quality of the clustering is measured by the maximum distance between any data point and its nearest cluster center.

The best possible quality is achieved by optimally placing the cluster centers to minimize this maximum distance. Determine this maximum distance between any data point and its nearest cluster center.

Note: The distance between two feature points x and y is defined as |x - y|, where |x| denotes the absolute value of x.

My deepest and boundless gratitude to the incredible friend who so kindly shared this resource! 🐳

Function

getMaximumDistance(location: int[], k: int) → int

Examples

Example 1

location = [4, 1, 6, 7, 2]k = 2return = 2
Example 1 illustration

More Fortinet interview questions

  • Checksum AggregatorOA · Seen Jun 2025
  • Madam C.J. Walker's Business PlanOA · Seen Jun 2025
  • Signal PingsOA · Seen Jun 2025
  • Maximize Beautiful SubstringsOA · Seen Mar 2025

Similar questions at other companies

  • Find Minimum TimeAlphaSense · OA
  • Find Minimum TimeBlackRock · OABlackRock interview questions
  • Shortest Board Length to Cover HolesMicrosoft · OAMicrosoft interview questions
  • Minimize Maximum Group DifferenceDRW · OADRW interview questions
  • Minimum-Cost Solar Rooftop AllocationDeloitte · OADeloitte interview questions
  • Playlist PartitioningTikTok · OATikTok interview questions
  • Get Minimum Pen Drive SizeAmazon · OA
  • Collect PointsFlexport · OAFlexport interview questions
  • Aggressive CowsPeopleStrong · OAPeopleStrong interview questions
  • Spread Cows Across StallsExpedia · OAExpedia interview questions
All Fortinet interview questionsSee Fortinet hiring insights
Saved
class Solution {
    public int getMaximumDistance(int[] location, int k) {
      // write your code here
    }

}
Checking account…