Problem statement

https://leetcode.com/problems/minimum-time-visiting-all-points/

Solution

Just do what is asked: for two adjacent points we need to spend max(W, H) time, where W and H are vertical and horizontal distances.

Complexity

Time complexity is O(n), space is O(1).

Code

class Solution:
    def minTimeToVisitAllPoints(self, P):
        return sum(max(abs(x2-x1), abs(y2-y1)) for (x1, y1), (x2, y2) in zip(P, P[1:]))