C++ Binary Search O(nlogm)
This Binary Search is giving the index of the last value from nums2 which is greater than or equal to nums[i]. Here left = the current i in nums1\n- Time comple
This Binary Search is giving the index of the last value from nums2 which is greater than or equal to nums[i]. Here left = the current i in nums1\n- Time complexity : O(nlogm)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n```\n\nclass Solution \n{\npublic:\n    int binary_search(vector<int> &nums2,int start,int target)\n    {\n        int left=start,right=nums2.size()-1,mid;\n        while(left<=right)\n        {\n            mid=left+(right-left)/2;\n            nums2[mid]>=target? left=mid+1 : right=mid-1;\n        }\n        return right;\n    }\n    int maxDistance(vector<int>& nums1, vector<int>& nums2) \n    {\n        int i=0,j,m=0,num=-1;\n        for(i=0;i<nums1.size() && i<nums2.size();i++)\n        {\n            if(nums1[i]!=num) // IF nums[i]!=nums[i-1]\n            {\n                j = binary_search(nums2,i,nums1[i]);\n                if(j>i) m = max(m,j-i);\n            }\n            num = nums1[i];\n        }\n        return m;\n    }\n};\n```
['C++']