One Line Iterative solution  | Greedy approach | Two pointers || Single Pas || Sorting
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nIf you read the problem statement carefully, you can observe at any point
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nIf you read the problem statement carefully, you can observe at any point you have to take care you two values at a time i.e weights in this case so take two people and check whether they can be added in a same boat or both have to take a separate i.e One of them is bigger in size which is causing unbalance in the boat\n\nSo, 1st point of making mistake is you sort the array but you check the adjacent elements and compute you answers for the testcases you would pass but think broadly, let say in a bag that can hold 10 kg and we have four items [1kg,5kg,7kg,9kg] what would you select that would give you a maximum at any instant.\n\n\nYou can keep two pointers after sorting to see if the larger value can be paired with the smallest one or it. Greedily this is the only way you can see the minimum out of all feasile solution\n\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: Single Pass- 0(N logn)\n- We sort the array so the time complexity in worst case is O(nlogn)\n- for custom sorting behaviour\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: 0(logn)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int numRescueBoats(vector<int>& people, int limit) {\n        int n = people.size();\n        sort(people.begin(),people.end());\n        int ans = 0;\n\n        int i=0,j=n-1;\n        while(i<=j)\n        {\n            if(people[i]+people[j] <= limit)\n            {\n                i++;j--;\n                ans++;\n            }\n            else \n            {\n                ans++;\n                j--;\n            }\n        }\n        return ans;\n    }\n};\n```
['Array', 'Two Pointers', 'Greedy', 'Sorting', 'C++']