✅✅Faster || Easy To Understand || C++ Code
Approach 1 :- Using Binary Seacrh\n\n Time Complexity :- O(NlogN)\n\n Space Complexity :- O(1)\n\n\nclass Solution {\npublic:\n    int maxDistance(vector<int>& 
* ***Approach 1 :- Using Binary Seacrh***\n\n* ***Time Complexity :- O(NlogN)***\n\n* ***Space Complexity :- O(1)***\n\n```\nclass Solution {\npublic:\n    int maxDistance(vector<int>& nums1, vector<int>& nums2) {\n        \n        int n1 = nums1.size();\n        \n        int n2 = nums2.size();\n        \n        int maxi = 0;\n        \n        for(int i = 0; i < n1; i++)\n        {\n            // find the element from right side which is greater than equal to nums1[i]\n            \n            int idx = lower_bound(nums2.rbegin(), nums2.rend(), nums1[i]) - nums2.rbegin();\n            \n            // find the index of that number from right side\n            \n            idx = n2 - idx - 1;\n            \n            // update maxi\n            \n            if(idx >= i)\n            {\n                maxi = max(maxi, idx - i);\n            }\n        }\n        \n        return maxi;\n    }\n};\n```\n\n* ***Approach 2 :- Using Two Pointer***\n\n* ***Time Complexity :- O(N)***\n\n* ***Space Complexity :- O(1)***\n\n```\nclass Solution {\npublic:\n    int maxDistance(vector<int>& nums1, vector<int>& nums2) {\n        \n        int n1 = nums1.size();\n        \n        int n2 = nums2.size();\n        \n        int maxi = 0;\n        \n        int i = 0;\n        \n        int j = 0;\n        \n        while(i < n1 && j < n2)\n        {\n            // if element of nums1 is less than element of nums2\n            \n            // just increment the i\n            \n            if(nums1[i] > nums2[j])\n            {\n                i++;\n            }\n            else\n            {\n                j++;\n            }\n            \n            // update maxi\n            \n            maxi = max(maxi, j - i - 1);\n        }\n        \n        return maxi;\n    }\n};\n```
['Two Pointers', 'C', 'Binary Tree', 'C++']