TypeScript Solution: (Beats 100%) (Two Pointers) (O(M + N)) ✔📜
Approach\nWe will mark the two arrays with p1, p2 then we will try to catch the max gap between i, j.\n\n# Complexity\n- Time complexity: O(n + m)\n\n- Space co
# Approach\nWe will mark the two arrays with `p1`, `p2` then we will try to catch the max gap between `i`, `j`.\n\n# Complexity\n- Time complexity: $$O(n + m)$$\n\n- Space complexity: $$O(1)$$\n\n# Code\n```ts\nfunction maxDistance(nums1: number[], nums2: number[]): number {\n    let p1 = 0, p2 = 0, ans = 0;\n    while ( p1 < nums1.length && p2 < nums2.length ) {\n\n        /* \n            If nums1[p1] is larger then we need to go one step\n            to decrease nums1[p1]\n         */\n        if ( nums1[p1] > nums2[p2] ) p1++;\n        /*\n            check if this diff is the max or not then take the max diff\n        */\n        else {\n            ans = Math.max(ans, p2 - p1);\n            p2++;\n        }\n    }\n\n    return ans;\n};\n```
['Array', 'Two Pointers', 'Greedy', 'TypeScript']