Fast solution
Code\n\nclass Solution {\npublic:\n    int numRescueBoats(vector<int>& people, int limit) {\n        // Sort the list of people in ascending order of weight\n  
# Code\n```\nclass Solution {\npublic:\n    int numRescueBoats(vector<int>& people, int limit) {\n        // Sort the list of people in ascending order of weight\n        sort(people.begin(), people.end());\n        // Initialize pointers for the lightest and heaviest person\n        int left = 0;\n        int right = people.size() - 1;\n\n        // Initialize the number of boats needed\n        int boats = 0;\n\n        // Loop through the list of people until all people have been rescued\n        while (left <= right) {\n            // Check if the lightest and heaviest person on the same boat can\n            // fit\n            if (people[left] + people[right] <= limit) {\n                // If they can, move on to the next lightest person\n                left++;\n            }\n            // Move on to the next heaviest person\n            right--;\n\n            // Add a boat for the current group of people\n            boats++;\n        }\n        // Return the total number of boats needed\n        return boats;\n    }\n};\n```
['C++']