Binary Search Python Explained
Intuition\nThrough the given problem we have few conditions\n1. j >= i\n2. nums2[j] > nums1[i]\n\nNow to satisfy these conditions for every element in of nums1 
# Intuition\nThrough the given problem we have few conditions\n`1. j >= i`\n`2. nums2[j] > nums1[i]`\n\nNow to satisfy these conditions for every element in of nums1 we have to iterate over nums2(i, len(nums2))\n\nso we will use **binary search** having the above range always\nnow if we find *nums[mid] < nums1[i] => we can\'t consider* this thus shift ur right\n\nif *nums[mid] >= nums1[i] => we know the array is in descending order so store this mid index values as farthestSeen* now and shift left pointer.\n\n`why not return here?` Because to get the farthest position we have to find element > nums1[i] as far as possible from i\n\nCalculate the diff(j-i) and return the maxDiff as your ans :)\n\n# Code\n```\nclass Solution:\n    def maxDistance(self, nums1: List[int], nums2: List[int]) -> int:\n        def binary(left, right, num):\n            farthestPos = 0\n            while left < right:\n                mid = (left + right) // 2\n                if nums2[mid] < num:\n                    right = mid\n                else:\n                    farthestPos = max(farthestPos, mid)\n                    left = mid + 1\n            if nums2[left] >= num:\n                farthestPos = max(farthestPos, left)\n            return farthestPos\n        maxDiff = 0\n        for i in range(min(len(nums1), len(nums2))):\n            if nums1[i] > nums2[i]:\n                continue\n            else:\n                j = binary(i, len(nums2)-1, nums1[i])\n                maxDiff = max(maxDiff, (j-i))\n        return maxDiff\n```
['Array', 'Binary Search', 'Python3']