Maximum Distance in Arrays
Input:
[[1,2,3],
[4,5],
[1,2,3]]
Output:
4
Explanation:
One way to reach the maximum distance 4 is to pick 1 in the first or third array and pick 5 in the second array.class Solution(object):
def maxDistance(self, arrays):
"""
:type arrays: List[List[int]]
:rtype: int
"""
res = 0
start, end = arrays[0][0], arrays[0][-1]
for row in arrays[1:]:
res = max(res, abs(row[-1] - start))
res = max(res, abs(end - row[0]))
start = min(start, row[0])
end = max(end, row[-1])
return resLast updated