Minimum Time Visiting All Points

Problem Id: 1266 Difficulty: Easy Tag: Array Tag: Geometry


Intuition

Very simple problem, the only diffcult part in this problem is to calculate distance between 2 points. And the distance would be the max value of delta x and delta y.

Solution


class Solution:
    def minTimeToVisitAllPoints(self, points: List[List[int]]) -> int:
        x, y = points[0]
        ans = 0
        for i, j in points[1:]:
            m, n = abs(x - i), abs(y - j)
            ans += min(m, n) + abs(m - n)
            x, y = i, j
        return ans