Zepruv › Coding problems

Maximum Distance in Arrays

Medium · Array, Greedy

You are given m arrays, where each array is sorted in ascending order.
You can pick up two integers from two different arrays (each array picks one) and calculate the distance. We define the distance between two integers a and b to be their absolute difference |a - b|.
Return the maximum distance.

Example 1

Input: arrays = [[1,2,3],[4,5],[1,2,3]]
Output: 4

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.

Example 2

Input: arrays = [[1],[1]]
Output: 0

Constraints

Starter code (python)

class Solution(object):
    def maxDistance(self, arrays):
        """
        :type arrays: List[List[int]]
        :rtype: int
        """
        

Related problems

Previous: Add One Row to Tree · Next: Maximum Product of Three Numbers · All problems

Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.