Minimum Time Visiting All Points

Easy

Description

On a 2D plane, there are n points with integer coordinates. Return the minimum time in seconds to visit all points in the order given. You can move one unit per second in any of the 8 directions.

Examples

Input:points = [[1,1],[3,4],[-1,0]]
Output:7
Explanation:

[1,1] to [3,4] = 3s, [3,4] to [-1,0] = 4s

Input:points = [[1]]
Output:0
Explanation:

With only one point to visit, no movement is needed, so the time is 0 seconds.

Input:points = [[0,0],[2,2],[0,4]]
Output:6
Explanation:

From [0,0] to [2,2]: moving diagonally takes 2 steps (2 seconds). From [2,2] to [0,4]: moving 2 units left and 2 units up takes max(2,2) = 2 seconds using diagonal movement. Total: 2 + 4 = 6 seconds.

Constraints

  • points.length == n
  • 1 ≤ n ≤ 100

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!