✅ [C++] Intuitive 2 pointers method
\nclass Solution {\npublic:\n    int maxDistance(vector<int>& nums1, vector<int>& nums2) {\n        int i = 0, j = 0;\n        int ans = 0;\n\t\t// One pointer 
```\nclass Solution {\npublic:\n    int maxDistance(vector<int>& nums1, vector<int>& nums2) {\n        int i = 0, j = 0;\n        int ans = 0;\n\t\t// One pointer is at first array, another is at 2nd array. \n        while(i<nums1.size() and j<nums2.size()){\n\t\t\t// If i is greater than j, we move j to satisfy the conditions. \n            if(i>j){ \n                j++;\n                continue;\n            }\n\t\t\t// The above condition is already satisfied. If the below satisfies too, we update the answer AND move j\n\t\t\t// in the hope of finding a better answer for current i. NOTE we need to maximize the gap (j-i\n            if(nums1[i]<=nums2[j]){\n                ans = max(ans,j-i);\n                j++;\n            }\n            else\n                i++;            // If the condition is not satisfied for current i, we move i\n        }\n\t\t// If nums2 has not been fully traversed yet, we traverse it with the additional while loop and check our \n\t\t// answer with the last element of nums1.\n        while(j<nums2.size()){\n            if(nums1.back()<=nums2[j]){\n                int temp = j-(nums1.size()-1);\n                ans = max(ans,temp);\n            }\n            j++;\n        }\n\t\t\n\t\t// NOTE that we are not doing this for nums1, because it would be of no good! If we finish nums2\n\t\t// before nums1, then j will always be less than i and thus our conditions will not be satisfied.\n        return ans;\n    }\n};\n```
['Two Pointers', 'C']