[C++] Binary Search nlogn
\nclass Solution {\npublic:\n    \n    int binarySearch(vector<int>& nums1, int val){\n        int l = 0, h = nums1.size()-1;\n        int ind = 1e9;\n        w
```\nclass Solution {\npublic:\n    \n    int binarySearch(vector<int>& nums1, int val){\n        int l = 0, h = nums1.size()-1;\n        int ind = 1e9;\n        while(l<=h){\n            int mid = l + (h-l)/2;\n            if(nums1[mid] > val){\n                l = mid+1;\n            }else{\n                ind = mid;\n                h = mid-1;\n            }\n        }\n        return ind;\n    }\n    \n    int maxDistance(vector<int>& nums1, vector<int>& nums2) {\n        int n = nums1.size();\n        int m = nums2.size();\n        int res = INT_MIN;\n        for(int j=m-1; j>=0; j--){\n            res = max(res,j - binarySearch(nums1,nums2[j]));\n        }\n        return res<0 ? 0:res;\n    }\n};\n```
['C', 'Binary Tree']