Easy cpp,python code using two pointer approach
Intuition\n Describe your first thoughts on how to solve this problem. \nThe goal is to find the maximum distance j - i such that n1[i] <= n2[j]. Since both arr
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe goal is to find the maximum distance j - i such that n1[i] <= n2[j]. Since both arrays n1 and n2 are sorted in non-increasing order, we can utilize the two-pointer technique to efficiently compute the result.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Two Pointers (i and j):\n\n- i starts at the beginning of n1, representing the current element in n1.\n- j starts at the beginning of n2, representing the current element in n2.\n2. Condition Check:\n\n- For each i, if n1[i] > n2[j], increment i because this is not a valid pair (since n1[i] is greater than n2[j]).\n- If n1[i] <= n2[j], calculate the distance j - i and update the maximum distance x. \nThen increment j to try and find a larger distance.\n3. Termination:\n- The loop continues as long as both i and j are within the bounds of their respective arrays.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nSince both pointers traverse through the arrays once without backtracking, the time complexity is O(n), where n is the size of the arrays. This is efficient\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1), as we only use a few extra variables.\n\n# Code\n\n```python []\nclass Solution:\n    def maxDistance(self, n1: List[int], n2: List[int]) -> int:\n        x = 0\n        i = 0\n        j = 0\n        \n        while i < len(n1) and j < len(n2):\n            if n1[i] > n2[j]:\n                i += 1  \n            else:\n                x = max(x, j - i)  \n                j += 1  \n        return x\n\n```\n\n```cpp []\nclass Solution {\npublic:\n    int maxDistance(vector<int>& n1, vector<int>& n2) {\n        int x=0,i=0,j=0;\n        while(i<n1.size() && j<n2.size())\n        {\n            if(n1[i]>n2[j])\n            {\n                i++;\n            }else\n            {\n                x=max(x,j-i);\n                j++;\n            }\n        }\n        return x;\n    }\n};\n```
['Array', 'Two Pointers', 'C++', 'Python3']