JAVA | Binary Search
Approach\nTraverse in nums1 and for each index use binary search to find the index of farthest equal element or greater element in nums2.\n\n# Code\n\nclass Sol
# Approach\nTraverse in nums1 and for each index use binary search to find the index of farthest equal element or greater element in nums2.\n\n# Code\n```\nclass Solution {\n    public int binarySearch(int[] arr, int i, int target){\n        int low = i, high = arr.length-1;\n        int res = -1;\n        \n        while(low<=high){\n            int mid = high - (high-low)/2;\n            if(arr[mid] >= target){\n                res = Math.max(mid, res);\n                low = mid+1;\n            }\n            else{\n                high = mid-1;\n            }\n        }\n        return res;\n    }\n    public int maxDistance(int[] nums1, int[] nums2) {\n        int max = 0;\n        for(int i=0; i<nums1.length; i++){\n            int j = binarySearch(nums2, i, nums1[i]);\n            max = Math.max(max, j-i);\n        }\n        return max;\n    }\n}\n```
['Java']