Skip to content

Practice Minimum Total Distance Traveled

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2463
LeetCode Problem

Minimum Total Distance Traveled

Problem Statement

robot gives distinct robot positions and factory contains [position,limit] for distinct factory locations. Choose when to start each robot and its initial left or right direction; it then travels at the common speed until the first factory with spare capacity repairs it. Full factories are passed, and robots cross without collision. Return the minimum total distance to repair every robot; sufficient capacity and a valid schedule are guaranteed.

Source: Minimum Total Distance Traveled on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
robot = [0,4,6], factory = [[2,2],[6,2]]
Output
4

# Example 2

Input
robot = [1,-1], factory = [[-2,1],[2,1]]
Output
2

Constraints

1 <= robot.length, factory.length <= 100
factory[j].length == 2
-10^9 <= robot[i], positionj <= 10^9
0 <= limitj <= robot.length
The input will be generated such that it is always possible to repair every robot.

Related LeetCode Problems

Practice more problems similar to Minimum Total Distance Traveled.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.