Easy Two Pointer Approach with Explanation
Step 1: Sort The Given vector using inbuilt stl sort.\nStep 2: Initialize two pointers i and j (i=0 and j = n-1)\nStep 3 : initialize one counter variable ans a
**Step 1**: Sort The Given vector using inbuilt stl sort.\n**Step 2**: Initialize two pointers i and j (i=0 and j = n-1)\n**Step 3** : initialize one counter variable ans as zero .\n**Step 4** : iterate till i<=j and keep increasing ans variable.\n**Step : 5** return ans;\n**Step 6** : Comment down your approach please\n\n\n```\nclass Solution {\npublic:\n    int numRescueBoats(vector<int>& people, int limit) {\n    sort(people.begin(),people.end());\n    int i = 0;\n    int j = people.size()-1;\n    int ans = 0;\n    while(i<=j){\n        if(people[i]+people[j]<=limit){\n            i++;\n            j--;\n        }else{\n            j--;\n        }\n        ans++;\n    }\n    return ans;\n    \n        \n    }\n};\n```
['Two Pointers', 'C', 'C++']