Airbnb Intern OA
  1. Disk Clustering

The hard disk of a computer has n sectors, where the size stored in the iᵗʰ sector is denoted by sectorCost[i], for all 1 ≤ i ≤ n. The hard disk needs to be divided into exactly clusterCount clusters. A cluster division of a hard disk into clusterCount parts looks like this:

  • sectorCost[1, ..., x₁], sectorCost[x₁ + 1, ..., x₂], ..., sectorCost[xₙ₋₁ + 1, ..., n].

The cost of cluster division into a part [x, ..., y] is defined as sectorCost[x] + sectorCost[y].

Find the minimum and the maximum possible costs of cluster division. Return an array of 2 elements where the first element represents the minimum possible cost of clustering and the second element represents the maximum possible cost of clustering.

Example

Given n = 5, sectorCost = [1, 2, 3, 2, 5] and clusterCount = 3.

Minimum Cost -
If the disk is clustered as [1], [2], [3, 2, 5].
Cost of partitioning = (sectorCost[1] + sectorCost[1]) + (sectorCost[2] + sectorCost[2]) + (sectorCost[3] + sectorCost[5])
= (1 + 1) + (2 + 2) + (3 + 5) = 14. (1-based indexing)

Maximum Cost -
If the disk is clustered as [1, 2, 3], [2], [5].


经过csoahelp的面试辅助,候选人获取了良好的面试表现。如果您需要面试辅助面试代面服务,帮助您进入梦想中的大厂,请随时联系我

If you need more interview support or interview proxy practice, feel free to contact us. We offer comprehensive interview support services to help you successfully land a job at your dream company.

Leave a Reply

Your email address will not be published. Required fields are marked *