C++ | Simple Binary Search Inspired by Two Sum
\nclass Solution {\n    int find(vector<int>& arr,vector<int>& vis,int lo,int lim,int target){\n        int hi = arr.size() - 1,ans = -1;\n        while(lo <= h
```\nclass Solution {\n    int find(vector<int>& arr,vector<int>& vis,int lo,int lim,int target){\n        int hi = arr.size() - 1,ans = -1;\n        while(lo <= hi){\n            int mid = lo + (hi - lo)/2;\n            if(arr[mid] <= target && !vis[mid]){\n                lo = mid + 1;\n                ans = mid;\n            }else{\n                hi = mid - 1;\n            }\n        }\n        \n        return ans;\n    }\npublic:\n    int numRescueBoats(vector<int>& arr, int limit) {\n       sort(arr.begin(),arr.end());\n        int cnt = 0;\n        vector<int> vis(arr.size());\n        for(int i=0;i<arr.size();i++){\n            int target = limit - arr[i];\n            if(!vis[i]){\n                if(target > 0){\n                    int idx = find(arr,vis,i,limit,target);\n                    if(idx != -1){\n                        vis[idx] = 1;\n                    }\n                }\n                cnt++;\n                vis[i] = 1;\n            }\n        }\n        \n        return cnt;\n    }\n};\n```\n\nTime Complexity would be - O(nlogn)\nSpace Complexity would be - O(n)
['Binary Search', 'C', 'Sorting', 'Binary Tree', 'C++']