Minimum Time Visiting All Points

EasyMathmath

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

You are given points, a list of integer coordinates [x, y] on a grid. Starting at points[0], you must visit the points **in the given order**. In one second you can move one unit horizontally, one unit vertically, or one unit diagonally (one unit in both x and y at once). You may pass through later points early, but that does not count as visiting them. Return the minimum number of seconds needed to visit every point in order.

Examples

Input: points = [[1,1],[3,4],[-1,0]]
Output: 7
Reaching `[3,4]` takes 3 seconds and then reaching `[-1,0]` takes 4 more.
Input: points = [[3,2],[-2,2]]
Output: 5
The points share a row, so it is 5 horizontal steps.

Constraints

  • 1 <= points.length <= 100
  • points[i].length == 2
  • -1000 <= points[i][0], points[i][1] <= 1000

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More math problems