Python | Binary Search
Approach:\n1. For each element in nums1, we perform binary search on nums2 to find the index of the right-most element which is greater than or equal to the cur
Approach:\n1. For each element in nums1, we perform binary search on nums2 to find the index of the right-most element which is greater than or equal to the current element in nums1.\n2. Since nums2 may contain duplicate elements, to move to the right-most element we need to make mid as right-biased by using mid = l + (r-l+1)/2\n3. We have three cases in binary search:\n*  nums2[mid] < target: r = mid - 1\n*  nums2[mid] > target: l = mid + 1\n*  nums2[mid] = target: l = mid\nAfter Combining case 2 and case 3, we can say that if nums2[mid] >= target: l = mid\n4. Loop terminates when l and r become equal  \n \n```\nclass Solution(object):\n    def maxDistance(self, nums1, nums2):\n        """\n        :type nums1: List[int]\n        :type nums2: List[int]\n        :rtype: int\n        """\n        def binarySearch(start, target):\n            l, r = start, len(nums2)-1\n            while l < r:\n                mid = l + (r-l+1)/2\n                if nums2[mid] < target:\n                    r = mid - 1\n                else:\n                    l = mid\n            \n            if nums2[r] >= target:\n                return r\n            else:\n                return -1\n        maxDistance = 0        \n        for i in range(len(nums1)):\n            j = binarySearch(i, nums1[i])\n            if j != -1:\n                maxDistance = max(maxDistance, j-i)\n        return maxDistance        \n```
['Binary Tree', 'Python']