# 1266. Minimum Time Visiting All Points

T: O(n)

S: O(1)

````java
```java
class Solution {
    public int minTimeToVisitAllPoints(int[][] points) {
        int result = 0;
        for (int i = 0; i < points.length-1; i++) {
            int XCurr = points[i][0];
            int XNext = points[i+1][0];

            int YCurr = points[i][1];
            int YNext = points[i+1][1];

            result += Math.max(Math.abs(XCurr - XNext), Math.abs(YCurr - YNext));
        }
        return result;
    }
}
```

```java
/**


why min dist is max(diffX, diffY)?


because when we move x -> actually we also move y (by diagnal way)

so if we move x, but still can't arrive, the left is diffY - diffX) (this is positive number)

so we only need to know which is bigger -> so it's max(diffX, diffY)

key point is it can move by "diagnal way"

ex: [1,1],[3,4]

4               3,4

3               x -> 2 units (x can diagnal walk 2 units), then just vertically move to 3,4 by 1 units

2         x
  
1    1,1
      1    2    3

      max(abs(3-1), abs(4-1)) = max(2, 3) = 3
 */
```
````


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://timmybeeflin.gitbook.io/cracking-leetcode/weekly-contest/1266.-minimum-time-visiting-all-points.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
