[C++] Brute - Better - Optimal
Brute Force (TLE):\n\n# Code\n\nclass Solution {\npublic:\n    int maxDistance(vector<int>& nums1, vector<int>& nums2){\n        int n1=size(nums1),n2=size(nums
# Brute Force (TLE):\n\n# Code\n```\nclass Solution {\npublic:\n    int maxDistance(vector<int>& nums1, vector<int>& nums2){\n        int n1=size(nums1),n2=size(nums2),res=0;\n        for(int i=0;i<n1;i++){\n            for(int j=i;j<n2;j++) {\n                if(nums1[i]<=nums2[j]) res=max(best,j-i);\n            }\n        }\n        return res;\n    }\n};\n```\n# Complexity\n- Time complexity: $$O(n*m)$$\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\n# Better :\n\n# Code\n```\nclass Solution {\npublic:\n    int maxDistance(vector<int>& nums1, vector<int>& nums2){\n        int n1=size(nums1),n2=size(nums2),res=0; \n        for(int i=0;i<n1;i++){\n            int val=nums1[i];\n            int l=i,r=n2-1;\n            while(l<=r){\n                int mid=l+(r-l)/2;\n                if(nums2[mid]>=val){\n                    res=max(res,mid-i);\n                    l=mid+1;\n                }\n                else r=mid-1;\n            }\n        }\n        return res;\n    }\n};\n```\n# Complexity\n- Time complexity: $$O(n*log(m))$$\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---\n\n\n\n# Optimal :\n\n# Code\n```\nclass Solution {\npublic:\n    int maxDistance(vector<int>& nums1, vector<int>& nums2){\n        int n1=size(nums1),n2=size(nums2),res=0;\n        for(int i=0,j=0;i<n1&&j<n2;){\n            if(nums1[i]<=nums2[j]) res=max(res,(j++)-i);\n            else i++;\n        }\n        return res;\n    }\n};\n```\n# Complexity\n- Time complexity: $$O(n+m)$$\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\n
['Two Pointers', 'Binary Search', 'C++']