Two pointer Approach || C++|| Simple & easy || easy to understand
Algorithm\n1. Sort the vector to know the weight of person in increasing order.\n2. Using  Two pointer approach  , we traverse the whole vector.\n\t \tif the su
**Algorithm**\n1. **Sort the vector** *to know the weight of person in increasing order.*\n2. Using  ***Two pointer approach***  , we traverse the whole vector.\n\t* \tif the **sum of weight of heaviest person and lightest person is less than or equal to limit** , we **increament the left poointer(i)** , **decreament the right pointer(j)** and **increament the value of count** variable by 1 because the weight sum of both person is not exceed the limit so both person can be carried by a single boat.\n\t* \tif the **weight sum of both person exceed the limit** then it is assured that only heavy person can be carry by one boat so we carry that heavy person only  so we **decreament the right pointer (j)** and **increament the count variable** by 1.\n\t* \tthis process is run until the left pointer is less than or equal to right pointer \n\t* \t**When the value of left pointer(i) is greater than right pointer(j) , we break the loop and return the value of count.**\n3. ***THUS  WE HAVE SOLVED THE PROBLEM***\n\t\t\t\t\t**IF YOU FIND IT HELPFUL , UPVOTE PLEASE**\n\t\t\t\t\t\n\t\t\t\t\t\n```\nclass Solution {\npublic:\n    int numRescueBoats(vector<int>& people, int limit) {\n        int count = 0;\n\t\tsort(people.begin() , people.end()); \n        int n = people.size();\n        int i = 0 , j = n - 1;\n        while(i <= j)\n        {\n            if(people[i] + people[j] <= limit)\n            {\n                i ++;\n                j --;\n                count ++;\n            }\n            else\n            {\n               j --;\n               count ++;\n            }\n        }\n        return count;\n    }\n};\n```\nTime complesity :- O(nLogn)\nspace complexity :- O(1)\n\n***THANK YOU***
['C']