Skip to content
LC-1855 Medium LeetCode

1855. Maximum Distance Between a Pair of Values

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 54% Topics: Array, Two Pointers, Binary Search
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n + m)
# Space: O(1)

class Solution(object):
    def maxDistance(self, nums1, nums2):
        """
        :type nums1: List[int]
        :type nums2: List[int]
        :rtype: int
        """
        result = i = j = 0
        while i < len(nums1) and j < len(nums2):
            if nums1[i] > nums2[j]:
                i += 1
            else:
                result = max(result, j-i)
                j += 1
        return result

Solution from kamyu104/LeetCode-Solutions · MIT