✅C++ | ✅Two Pointer |✅Binary Search|✅Easy O(N) and O(N*LogN)solution
Just a few words to explain the solution a bit.\nThere is Three Approaches for this problem comes in my mind.\n1.Brute force : check for every element in array 
Just a few words to explain the solution a bit.\n**There is Three Approaches for this problem comes in my mind.**\n**1.Brute force : check for every element in array A to every element of array B then store the result in maxx variable. return it. But this will gives you TLE because of it\'s time complexity is much high i.e. O(n^2).**\n\n**2.Binary Search : Since both of the given array are sorted so take any one array iterate over it and try to upperbound of reverse array in second array. Time complexity O(N*LogM)**\n\n```\nclass Solution {\npublic:\n    int maxDistance(vector<int>& nums1, vector<int>& nums2) {\n        int maxx = 0;\n        for(int i=0;i<nums1.size();i++){\n            int target = nums1[i];\n            vector<int>::iterator up;\n            up = upper_bound(nums2.begin(),nums2.end(),target, greater<int>());\n            int idx = up - nums2.begin();\n            maxx = max(maxx,idx-1-i);\n        }\n        return maxx;\n    }\n};\n```\n\n**3.Two pointer Approach. Time complexity is Linear. (Best Solution).**\n```\nclass Solution {\npublic:\n\tint maxDistance(vector<int>& nums1, vector<int>& nums2) {\n\t\tint ans = 0;\n\t\tint i = 0;\n\t\tint j = 0;\n\t\twhile(i < nums1.size() and j < nums2.size()){\n\t\t\tif(nums1[i] <= nums2[j]){\n\t\t\t\tif(i <= j){\n\t\t\t\t\tans = max(ans, j++ - i);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse{\n\t\t\t\ti++;\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n};\n```\n**PLEASE PLEASE..............UPVOTE ME**
['Binary Search', 'C', 'C++']