[C++] || Two pointer || Sorting || Easy
Upvote if helpful\n\n1. sort the people array\n2. set i =0 and j = n-1\n3. traverse and check the sum of people[i] and people[j] is less than or equal to limit 
*Upvote if helpful*\n```\n1. sort the people array\n2. set i =0 and j = n-1\n3. traverse and check the sum of people[i] and people[j] is less than or equal to limit \nif true {\n    count++;\n    j--;\n    i++;\n}\nelse{\n//assign boat to j and reduce j\n    count++; j--;\n}\n```\n**TC - O(n logn)**\n**SC - O(1)**\n**CODE**\n```\nclass Solution {\npublic:\n    int numRescueBoats(vector<int>& people, int limit) {\n        sort(people.begin(),people.end());\n        int n = people.size();\n        int ans=0;\n        int i=0,j = n-1;\n        while(i<=j){\n            if(people[i] + people[j] <= limit){\n                ans++;\n\t\t\t\ti++;  j--;\n            }\n            else{\n                ans++;\n\t\t\t\tj--;\n            }\n        }\n        return ans;\n    }\n};\n```
['Two Pointers', 'C']