Minimum Time Visiting All Points

You are given n integer points points[i] = [xi, yi] on a 2D plane. Return the minimum time in seconds to visit all of them in the given order. Each second you can move one unit vertically, one unit horizontally, or one unit diagonally (one unit in both directions at once). Passing through a later point early does not count as visiting it.

30:00

Minimum Time Visiting All Points
easy
Free written solution
Topics
Companies

You are given n integer points points[i] = [xi, yi] on a 2D plane. Return the minimum time in seconds to visit all of them in the given order. Each second you can move one unit vertically, one unit horizontally, or one unit diagonally (one unit in both directions at once). Passing through a later point early does not count as visiting it.

Example 1:
Input: {"points":[[1,1],[3,4],[-1,0]]}
Output: 7
Constraints:
  • points.length==n\text{points.length} == n

  • 1≤n≤1001 \leq n \leq 100

  • points[i].length==2\text{points}[i].\text{length} == 2

  • −1000≤points[i][0],points[i][1]≤1000-1000 \leq \text{points}[i][0], \text{points}[i][1] \leq 1000

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"points":[[1,1],[3,4],[-1,0]]}

Visit 3 points in order. Each second moves one unit sideways, up or down, or one unit diagonally.

the plane (purple = diagonal steps, blue = straight steps)

012

current leg

no leg yet

time = sum of max(dx, dy) per leg

= 0

Variables
VariableValue
n3
DepthFunction Call
Stack empty
0/6