Practice/Google/Leetcode 2463. Minimum Total Distance Traveled
CodingMust
You are managing a robotic warehouse system where robots need to be assigned to distribution warehouses for maintenance. All robots and warehouses are positioned along a single number line.
Given:
robots where robots[i] represents the position of the i-th robot on the number linewarehouses where warehouses[j] = [position_j, capacity_j] indicates that warehouse j is located at position_j and can service at most capacity_j robotsYour task is to assign every robot to exactly one warehouse such that:
The distance a robot travels is the absolute difference between its starting position and the warehouse position: |robot_position - warehouse_position|.
Return the minimum possible sum of distances traveled by all robots.
Example 1:
` Input: robots = [0, 4, 6], warehouses = [[2, 2], [6, 2]] Output: 4 Explanation:
Example 2:
Input: robots = [1], warehouses = [[2, 1]] Output: 1 Explanation: The single robot travels from position 1 to warehouse at position 2, distance = 1.
Example 3:
Input: robots = [9, 11, 99, 101], warehouses = [[10, 1], [7, 1], [14, 1], [100, 1], [96, 1]] Output: 18 Explanation: Optimal assignment considers both proximity and capacity constraints.