Binary Search Easy Solution || C++ || Beginner Friendly
\n# Time Complexity\nO(NLogM)\n\n# Code\n\nclass Solution {\n    int helper(vector<int>&nums,int tar,int i){\n        int st=i,en=nums.size()-1;\n        int ma
\n# Time Complexity\nO(NLogM)\n\n# Code\n```\nclass Solution {\n    int helper(vector<int>&nums,int tar,int i){\n        int st=i,en=nums.size()-1;\n        int maxi=INT_MIN;\n        while(st<=en){\n            int mid=st+(en-st)/2;\n            if(nums[mid]>=tar){\n                maxi=max(maxi,mid-i);\n                st=mid+1;\n            }\n            else{\n                en=mid-1;\n            }\n        }\n        return maxi;\n    }\npublic:\n    int maxDistance(vector<int>& nums1, vector<int>& nums2) {\n        int maxi=INT_MIN;\n        for(int i=0;i<nums1.size();i++){\n            maxi=max(maxi,helper(nums2,nums1[i],i));\n        }\n        return maxi==INT_MIN?0:maxi;\n    }\n};\n```
['Array', 'Two Pointers', 'Binary Search', 'C++']