C++ || Simple Two pointer approach :)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n- I\'ve used a Two pointer approach for this problem by wich i keep addin
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n- I\'ve used a Two pointer approach for this problem by wich i keep adding `left most` and `right most` of the elements.\n- then if the `sum` of those will be `<= limit` then increament the number of `boat` , `left` and decrease `right` elements.\n- and if sum is `>=limit` then just increase 1 `boat` and decrease `right`(cause only 1 person can sit now).\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(nlog(n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n## PS: Can someone tell me a `binary search approach` if possible? I\'m interested in that.\n\n`Upvote! It only takes 1 click :)`\n\n# Code\n```\nclass Solution {\npublic:\n    int numRescueBoats(vector<int>& people, int limit) {\n        sort(people.begin(), people.end());\n        int boat = 0;\n        int left = 0;\n        int right = people.size()-1;\n        while(left<=right){\n            int sum = people[left] + people[right];\n            if(sum<=limit){\n                boat++;\n                left++;\n                right--;\n            }\n            else{\n                boat++;\n                right--;\n            }\n        }\n        return boat;\n    }\n};\n```\n![Upvote.jpeg](https://assets.leetcode.com/users/images/efe86f36-bdd7-4cba-b575-379cc6edda42_1680507223.4331634.jpeg)\n
['Two Pointers', 'C++']