C++ Two Pointers
\nclass Solution {\npublic:\n    int numRescueBoats(vector<int>& people, int limit) {\n        //Time Complexity : O(nlogn)\n        //Space Complexity : O(1)\n
```\nclass Solution {\npublic:\n    int numRescueBoats(vector<int>& people, int limit) {\n        //Time Complexity : O(nlogn)\n        //Space Complexity : O(1)\n        \n        //sorted people in ascending ordere of their weight\n        sort(people.begin(),people.end());\n        //used this to store the index of maximum weight\n        int maxWeight=people.size()-1;\n        //used to store the index of minimum weight\n        int minWeight=0;\n        int ans=0;\n        //using two pointers approach \n        while(minWeight<=maxWeight){\n            //at most two persons can sit so checking the minimum and maximum weight \n            //if both satisfy the make them sit in one boat\n            if(people[minWeight]+people[maxWeight]<=limit){\n                minWeight++;\n                maxWeight--;\n            }\n            //otherwise maximum weight person will sit alone\n            else{\n                maxWeight--;\n            }\n            ans++;\n        }\n        return ans;\n    }\n};\n```
['Two Pointers', 'C', 'Sorting']