Easy C++ ✔|| Two Pointers || O(n+m)
\n# Approach\n Describe your approach to solving the problem. \n It first initializes two integer variables n and m with the sizes of nums1 and nums2, respectiv
\n# Approach\n<!-- Describe your approach to solving the problem. -->\n* It first initializes two integer variables `n` and `m` with the **sizes of nums1 and nums2**, respectively.\n* It then initializes three integer variables `i, j,` and `ans to 0`. * The variable `i` will be used to **iterate over nums1**, the variable `j` will be used to `iterate over nums2`, and the variable` ans` will store the maximum distance found so far.\n* It enters a **while loop** that continues as long as `i < n` and \n`j < m`. Inside the loop, it checks if **nums1[i] is greater than nums2[j]**. If so, it increments i. Otherwise, it updates ans with the maximum of ans and the difference between j and i, and then increments j.\n* After the loop finishes, it **returns ans**.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n+m)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n    int maxDistance(vector<int>& nums1, vector<int>& nums2) {\n        \n        int n=nums1.size();\n        int m=nums2.size();\n\n       int i=0,j=0;\n       int ans=0;\n\n       while(i<n && j<m){\n           if(nums1[i]>nums2[j]){\n                i++;\n           }\n           else{\n               ans=max(ans,j-i);\n               j++;\n           }\n       }\n       return ans;\n    }\n};\n```
['C++']