Skip to content
EasyArraysAI interview only

Minimum Time Visiting All Points

Asked atamazonmetagooglebloomberg

01 · Problem

You are given n points on a 2D grid as points[i] = [x_i, y_i]. You start at points[0] and must visit the points in the given order. In one second you can move by one unit horizontally, one unit vertically, or one unit diagonally (one unit in both x and y at the same time).

Return the minimum number of seconds needed to visit every point in order. Passing over a later point early does not count as visiting it; only the given order matters. If there is a single point, the answer is 0.

02 · Examples

Example 01
Input
points = [[1,1],[3,4],[-1,0]]
Output
7

From [1,1] to [3,4]: dx = 2, dy = 3, so 3 seconds. From [3,4] to [-1,0]: dx = 4, dy = 4, so 4 seconds. Total 7.

Example 02
Input
points = [[0,0],[2,5]]
Output
5

Move diagonally twice to [2,2], then up three times to [2,5]: max(2,5) = 5 seconds.

Example 03
Input
points = [[3,2],[-2,2]]
Output
5

The points share a y-coordinate, so the trip is 5 horizontal moves.

03 · Constraints

  • 011 <= points.length <= 100
  • 02points[i].length == 2
  • 03-1000 <= x_i, y_i <= 1000

04 · Optimal complexity

Time
O(n)
Space
O(1)
05 · Two ways to work on it

Practice it alone or rehearse it as an interview.

Practice Mode gives you an editor and test runs, nothing else. AI Interview Mode puts a voice interviewer on the other side, adds a clock, and ends with a scored summary of the round.