C++/ Binary Search /O(nlog n)
Intuition\nSince both arrays are sorted in a non-increasing way this means that for each value in the first array. We can find the farthest value smaller than i
# Intuition\nSince both arrays are sorted in a non-increasing way this means that for each value in the first array. We can find the farthest value smaller than it using binary search.\n\n# Approach\nSimply we use binary search here, we take one by one element of nums1 array and search element greater and equal to in nums2 array. if we found that then we simply take difference of that index with nums1\'s index and store in maxi variable and continue this process and at last we return maxi.\n\n# Complexity\n- Time complexity:\n  O(nlog n)\n\n# Code\n```\nclass Solution {\npublic:\n    int maxDistance(vector<int>& nums1, vector<int>& nums2) {\n       \n        int maxi=0;\n        for(int i=0;i<nums1.size();i++)\n        {   \n            int l=0;\n            int r=nums2.size()-1;\n            int target=nums1[i];\n            while(l<=r)\n            {\n                int mid=l+(r-l)/2;\n                if(nums2[mid]<target)\n                   r=mid-1;\n                else\n                {\n                   l=mid+1;\n                   maxi=max(maxi,mid-i);\n                }\n            }\n        }\n        return maxi;\n    }\n};\n```
['Binary Search', 'C++']