FastPrepHard Disk Clustering Cost
Problems/Hard Disk Clustering Cost

Hard Disk Clustering Cost

Confluent logoConfluent● HardFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Confluent online assessment. You split a row of disk sectors into a set number of back-to-back clusters, where each cluster costs its first plus its last sector, and return both the smallest and the largest total cost. The report gives the full task, the function name and one worked example.

It does not give any limits or the return type. Here, there are up to 10^5 sectors with sizes from 1 to 10^9, and both totals come back as long integers because they can pass the int range. The other two examples are ours.

Our version is about 95% the same as the reported question.

Given the sector sizes sectorCost of a hard disk and an integer clusterCount, return the minimum and the maximum possible cost of dividing the disk into exactly clusterCount clusters, as the array [minimum, maximum].

The disk has n sectors in a row, and sectorCost[i] is the size stored in sector i. A division splits the sectors into exactly clusterCount non-empty clusters of consecutive sectors, so that every sector belongs to exactly one cluster.

A cluster that runs from sector x to sector y costs sectorCost[x] + sectorCost[y]. A cluster of a single sector has x == y, so it costs twice that sector's size. The cost of a division is the sum of the costs of its clusters.

Function

getClusteringCost(sectorCost: int[], clusterCount: int) → long[]

Examples

Example 1

sectorCost = [1,2,3,2,5]clusterCount = 3return = [14,18]

The cheapest division is [1] [2] [3, 2, 5], which costs (1 + 1) + (2 + 2) + (3 + 5) = 14. The most expensive is [1, 2, 3] [2] [5], which costs (1 + 3) + (2 + 2) + (5 + 5) = 18. So the answer is [14, 18].

Example 2

sectorCost = [1,9,2,2]clusterCount = 2return = [7,14]

There are three ways to make two clusters. [1] [9, 2, 2] costs (1 + 1) + (9 + 2) = 13, [1, 9] [2, 2] costs (1 + 9) + (2 + 2) = 14, and [1, 9, 2] [2] costs (1 + 2) + (2 + 2) = 7. Cutting right after the smallest sector, 1, is not the cheapest, because the second cluster then starts at 9 and pays for it. So the answer is [7, 14].

Example 3

sectorCost = [1000000000,1000000000,500000000]clusterCount = 2return = [3000000000,3500000000]

[1000000000] [1000000000, 500000000] costs 2000000000 + 1500000000 = 3500000000, and [1000000000, 1000000000] [500000000] costs 2000000000 + 1000000000 = 3000000000. Both totals are larger than 2^31 - 1 = 2147483647, so they need 64-bit integers. The answer is [3000000000, 3500000000].

Constraints

  • n == sectorCost.length
  • 1 <= clusterCount <= n <= 10^5
  • 1 <= sectorCost[i] <= 10^9

More Confluent interview questions

  • Last Object to Fall Off the TableOA · Seen Nov 2026
  • Sum Symmetric Pairwise RemaindersOA · Seen Nov 2026
  • 0/1 KnapsackOA · Seen Nov 2026
  • Count Combinations Using Weights One Through KOA · Seen Oct 2026
  • Reach Target BalanceOA · Seen Mar 2026
  • Tail N LinesOA · Seen Mar 2026
  • Implement tail -nPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Sudoku Board ValidationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Sudoku Puzzle SolverPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Match a Variadic Function SignaturePHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Maximize K-Element AND with an Increment BudgetAmazon · OA
  • Delete and Freeze GameRubrik · OARubrik interview questions
  • Most Segments That Sort the ArrayRippling · OARippling interview questions
  • Most Items Within Budget from a Start IndexHudson River Trading · OAHudson River Trading interview questions
  • Luna and the Colorful SocksPhonePe · OAPhonePe interview questions
  • Minimum Starting Coins to Buy All ProductsMicrosoft · OAMicrosoft interview questions
  • Minimum Swaps to Sort a Ternary Array After UpdatesGoogle · OAGoogle interview questions
  • Disk ClusteringAirbnb · OAAirbnb interview questions
  • Get Max EfficiencySalesforce · OASalesforce interview questions
  • Finding a Hidden Benchmark ValueSamsung · OASamsung interview questions

Confluent interview experiences

  • Confluent Older Concurrency Rounds: 12 Experiences (Part 2 of 2)
  • Confluent Concurrency Interviews: 28 Experiences (Part 1 of 2)
  • Confluent SWE OA, Coding and Design Interviews: 19 Experiences
  • Confluent File Manipulation Round (tail -n): 19 Experiences
  • Confluent Coding and System Design Questions: 33 Questions
All Confluent interview questionsSee Confluent hiring insights
Saved
class Solution {
    public long[] getClusteringCost(int[] sectorCost, int clusterCount) {
      // Write your code here.
    }

}
Checking account…