Java Binary Search Solution and two pointer solution
O(nlogn) Solution\n\n\nclass Solution {\n    public int maxDistance(int[] nums1, int[] nums2) {\n        int res = 0;\n        for(int i = nums2.length-1; i >= 
**O(nlogn) Solution**\n\n```\nclass Solution {\n    public int maxDistance(int[] nums1, int[] nums2) {\n        int res = 0;\n        for(int i = nums2.length-1; i >= 0; i--) {\n            int start = 0, end = Math.min(nums1.length-1, i-1);\n            while(start <= end) {\n                int mid = start + (end - start) / 2;\n                if(nums1[mid] <= nums2[i]) {\n                    res = Math.max(res, i - mid);\n                    end = mid - 1;\n                }\n                else {\n                    start = mid + 1;\n                }\n                \n            }\n        }\n        return res;\n    }\n}\n```\n\nO(n) Solution\n\n```\nclass Solution {\n    public int maxDistance(int[] nums1, int[] nums2) {\n        int i=0, j=0;\n        int ans = 0;\n        while(i<nums1.length && j<nums2.length){\n            if(nums1[i]<=nums2[j]) ans = Math.max(j-i,ans);\n            if(i==j || nums1[i]<=nums2[j])  j++;\n            else  i++;\n        }\n        return ans;\n    }\n}\n```
[]