Python simple solution


  • 1
    H
    def maxDistance(self, arrays):
            a, b = heapq.nsmallest(2, [(l[0], i) for i, l in enumerate(arrays)])
            d, c = heapq.nlargest(2, [(l[-1], i) for i, l in enumerate(arrays)])
            return d[0] - a[0] if d[1] != a[1] else max(d[0] - b[0], c[0] - a[0])

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.