simple binary search || must see
Code\n\nstatic int fast_io = []() \n{ \n    std::ios::sync_with_stdio(false); \n    cin.tie(nullptr); \n    cout.tie(nullptr); \n    return 0; \n}();\n\n#ifdef 
# Code\n```\nstatic int fast_io = []() \n{ \n    std::ios::sync_with_stdio(false); \n    cin.tie(nullptr); \n    cout.tie(nullptr); \n    return 0; \n}();\n\n#ifdef LOCAL\n    freopen("input.txt", "r" , stdin);\n    freopen("output.txt", "w", stdout);\n#endif\n\nclass Solution {\npublic:\n    int maxDistance(vector<int>& nums1, vector<int>& nums2) \n    {\n        //we will use i to iterate over the nums1\n       \n        int ans = 0;\n\n        int i = 0;\n        while(i < (nums1.size()))\n        {\n            int j = fun(nums1[i],i,nums2.size()-1,nums2);\n\n            if(j != -1)\n            {\n                ans = max(ans,j-i);\n            }\n\n            i++;\n        } \n        return ans;\n    }\n    int fun(int &nums1,int start,int end,vector<int>&nums2)\n    {\n            int start_ = start;\n            int end_   = end;\n\n            int pos = -1;\n            while(start <= end)\n            {\n                int mid = (start + ((end - start)/2));\n\n                //either the nums[mid] could be smaller then the nums1\n                //either the nums[mid] could be greater then the nums1\n\n                if(nums2[mid] < nums1)\n                {\n                    end = mid-1;\n                }\n                else if(nums2[mid] >= nums1)\n                {\n                    pos = max(pos,mid);\n                    start = mid+1;\n                }\n            }      \n            if(start >= start_ and start <= end_ and nums2[start] >= nums1)\n            pos = max(pos,start);\n\n            if(end >= start_ and end <= end_ and nums2[end] >= nums1)\n            pos = max(pos,end);\n\n            return pos;\n    }\n};\n```
['Array', 'Two Pointers', 'Binary Search', 'Greedy', 'C++']