FastPrep.io has recently expanded its operations by establishing n distribution centers in a newly developed location in Cal. To efficiently manage the supply chain, they plan to set up two warehouses that will serve these distribution centers.
It is important to note that both the distribution centers and warehouses are positioned along a straight line. Each distribution center will have its demands fulfilled by the nearest warehouse.
A dedicated logistics team is tasked with determining the optimal locations for these two warehouses. Their primary objective is to minimize the total sum of distances between each distribution center and its closest warehouse, ensuring the most efficient and cost-effective supply chain operations.
Please complete function computeMinimumTotalDistance in the editor. This function has a parameter called distribution_center_locations, which is an integer array representing the positions of the distribution centers along the straight line. The function should return the minimum total distance between the distribution centers and the warehouses closest to them.
🦉Supa grateful for having a reliable helper like 🌷spike🌷 around 😊
distribution_center_locations = [1, 2, 3] return = 1

distribution_center_locations = [1, 6] return = 0
distribution_center_locations = [1, 2, 5, 6] return = 2
1 <= n <= 2*10^30 <= distribution_center_locations[i] <= 10^6(Updated on 02-05-2025, credit to spike :D- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Maximum Non-Adjacent House ValueONSITE INTERVIEW · Seen Jun 2026
- Running Delivery Time MediansONSITE INTERVIEW · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
public int computeMinimumTotalDistance(int[] distribution_center_locations) {
// write your code here
}