FunctionRacerProblemsRace

Minimum Time Visiting All Points

EasyMathPython, JavaScript, TypeScript, Java, C++

Each item points[i] = [x, y] of the list points is a spot on a grid, to be visited in the given order. In one second you may move one unit horizontally, one unit vertically, or one unit diagonally (both x and y change by 1).

Return the fewest seconds needed to visit all the points in order, starting at the first one.

Example 1

points [[1,1],[3,4],[-1,0]]
returns 7

(1,1) to (3,4) takes 3 seconds (2 diagonal, 1 up); (3,4) to (-1,0) takes 4. Total 7.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Math problems