c++ code | pure binary search approach | easy to comprehend | short and to the point
class Solution {\npublic:\n    int maxDistance(vector& nums1, vector& nums2) {\n        int ma_re=0;\n        for(int i=0;i<nums1.size();i=i+1)\n        {\n    
class Solution {\npublic:\n    int maxDistance(vector<int>& nums1, vector<int>& nums2) {\n        int ma_re=0;\n        for(int i=0;i<nums1.size();i=i+1)\n        {\n            int low=i;\n            int high=nums2.size()-1;\n            while(low<=high)\n            {\n                int mid=low+(high-low)/2;\n                if(nums1[i]>nums2[mid])\n                {\n                    high=mid-1;\n                }\n                else\n                if(nums1[i]<=nums2[mid])\n                {\n                    low=mid+1;\n                }\n                else\n                if(low==high)\n                    break;\n            }\n            if(low<nums2.size() && low>=0 && nums2[low]==nums1[i])\n            {\n                ma_re=max(ma_re,low-i);\n            }\n            else\n            {\n            ma_re=max(ma_re,low-i-1);\n            }\n            cout <<ma_re <<" ";\n        }\n        return ma_re;\n    }\n};\n
['Binary Search']