Two Pointer solution in C++ and Java
Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \n    O(n)\n\n- Space complexity:\n Add your space complexity here, e.g. O(n) \n    O(
# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    O(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    O(1)\n\n# Code\nJava Solution \n```\nclass Solution {\n    public int maxDistance(int[] nums1, int[] nums2) {\n        int i = 0, j = 0, ans = 0;\n        while(i < nums1.length&& j < nums2.length){\n        if(nums1[i] > nums2[j])\n            i++;\n        else{\n            ans = Integer.max(ans, j-i);\n            j++;\n        }\n    }\n    return ans;\n    }\n}\n```\nC++ solution\n```\nclass Solution {\npublic:\n    int maxDistance(vector<int>& nums1, vector<int>& nums2) {\n            int i = 0, j = 0, ans = 0;\n    while(i < nums1.size() && j < nums2.size()){\n        if(nums1[i] > nums2[j])\n            i++;\n        else{\n            ans = max(ans, j-i);\n            j++;\n        }\n    }\n    return ans;\n}\n};\n```\n
['Two Pointers', 'Binary Search', 'C++', 'Java']