Minimum Time Visiting All Points - Problem
On a 2D plane, there are n points with integer coordinates points[i] = [xi, yi]. Return the minimum time in seconds to visit all the points in the order given by points.
You can move according to these rules:
- In 1 second, you can either:
- Move vertically by one unit
- Move horizontally by one unit
- Move diagonally √2 units (in other words, move one unit vertically then one unit horizontally in 1 second)
You have to visit the points in the same order as they appear in the array. You are allowed to pass through points that appear later in the order, but these do not count as visits.
Input & Output
Example 1 — Basic Case
$
Input:
points = [[1,1],[3,4],[-1,0]]
›
Output:
7
💡 Note:
From [1,1] to [3,4]: max(|3-1|, |4-1|) = max(2,3) = 3 seconds. From [3,4] to [-1,0]: max(|-1-3|, |0-4|) = max(4,4) = 4 seconds. Total: 3 + 4 = 7 seconds.
Example 2 — Straight Line Movement
$
Input:
points = [[3,2],[-2,2]]
›
Output:
5
💡 Note:
From [3,2] to [-2,2]: max(|-2-3|, |2-2|) = max(5,0) = 5 seconds. Only horizontal movement needed.
Example 3 — Single Point
$
Input:
points = [[0,0]]
›
Output:
0
💡 Note:
Only one point, no movement required. Time = 0 seconds.
Constraints
- 1 ≤ points.length ≤ 100
- points[i].length == 2
- -1000 ≤ points[i][0], points[i][1] ≤ 1000
Visualization
Tap to expand
Understanding the Visualization
1
Input
Array of 2D coordinates representing points to visit in order
2
Process
Calculate Chebyshev distance between consecutive points
3
Output
Sum of all minimum travel times
Key Takeaway
🎯 Key Insight: Use Chebyshev distance (max of horizontal and vertical distances) since diagonal movement covers both axes simultaneously
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code