881. Boats to Save People

PHOTO EMBED

Mon Apr 03 2023 18:28:01 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

class Solution {
public:
    int numRescueBoats(vector<int>& people, int limit) {
        sort(people.begin(), people.end());
        int n=people.size();
        int ptri=0;
        int ptrl=n-1;
        int boats=0;
        
        for(ptrl=n-1;ptrl>=0&&ptrl>=ptri;ptrl--)
        {
            if(people[ptrl]+people[ptri]<=limit) ptri++;
            boats++;
        }
        return boats;
    }
};
content_copyCOPY

https://leetcode.com/problems/boats-to-save-people/