Ctrl K

Courier Robot Route

Easy
A courier robot drives on a grid and must visit the points stops strictly in the order listed, where stops[i] = [x, y]. It starts at the first point. Each second the robot moves one cell in any of eight directions: horizontally, vertically or diagonally, like a king in chess. It may pass through points whose turn has not come yet, but that does not count as visiting them. Return the fewest seconds the robot needs to visit every point.
Example 1
stops=[[0, 0], [3, 1], [3, -2]] → 6

To (3, 1): one diagonal step and two to the right, 3 seconds. Then three steps down to (3, -2), 3 more. 6 in total.

Example 2
stops=[[2, 2], [2, 2], [-1, 5]] → 3

The second stop coincides with the first and costs nothing. Then 3 diagonal steps.

Example 3
stops=[[7, -4]] → 0
Constraints
  • 1 ≤ len(stops) ≤ 100
  • stops[i] holds exactly two numbers
  • -1000 ≤ x, y ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Biggest Triangle on the Board EasyShadows of Block Towers EasySurface of Cube Towers EasyHow a Rumor Spreads EasyThree Stakes Off the Line Easy
loading Python…
Input
stops=[[0, 0], [3, 1], [3, -2]]
Expected
6

Run checks the first 3 tests in your browser. Submit checks all 123 tests on the server, hidden ones included.