Boats to Save People || c++ Greedy || two pointers || sorting || easy Solution with explaination
Think Greedily i.e try to accomodate maximum people in a boat\ntake two pointers which will be initially on start and end of array and as we will pick elements 
Think Greedily i.e try to accomodate maximum people in a boat\ntake two pointers which will be initially on start and end of array and as we will pick elements on pointers we wiil move the pointers forward and backward respectively.\n\ni) Sort the array and try to take two people with maximum weight(if possible) i.e from the last part of array.\nii) if not able to take two people of maximum weight ,then come to start of array and pick one element from start of the array.\n\nif its helpful Please Upvote the Solution !\n\n```\nclass Solution {\npublic:\n    int numRescueBoats(vector<int>& people, int limit) {\n        sort(people.begin(),people.end());\n        int i=0,j=people.size()-1;\n        int boats=1,count=0,peoplecount=0;\n        while(i<=j){\n            if(count+people[j]<=limit && peoplecount<2){\n                count+=people[j];\n                peoplecount++;//taking count of people in a boat\n                j--;\n            }\n            else if(count+people[i]<=limit && peoplecount<2){\n                count+=people[i];\n                 peoplecount++;//taking count of people in a boat\n                i++;\n            }else{\n                boats++;\n                count=people[j];\n                peoplecount=1;//taking count of people in a boat\n                j--;\n            }\n        }\n        return boats;\n    }\n};\n```\n\nPlease Go through my other discussed Problems : \nhttps://leetcode.com/problems/partition-labels/discuss/1868704/partition-labels-on-solution-c-greedy-simple-solution\nhttps://leetcode.com/problems/power-of-four/discuss/1799832/power-of-four-c100bit-manipualtion-easy-solution\nhttps://leetcode.com/problems/partition-labels/discuss/1868704/partition-labels-on-solution-c-greedy-simple-solution\nhttps://leetcode.com/problems/binary-tree-level-order-traversal/discuss/1862025/binary-tree-level-order-traversal-queue-binary-tree-easy-solution\nhttps://leetcode.com/problems/minimum-remove-to-make-valid-parentheses/discuss/1850726/minimum-remove-to-make-valid-parentheses-c-on-simple-logic-easy-solution\nhttps://leetcode.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/discuss/1849453/maximum-number-of-vowels-in-a-substring-of-given-length-csliding-window\nhttps://leetcode.com/problems/reverse-prefix-of-word/discuss/1840375/reverse-prefix-of-word-100-c\nhttps://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero/discuss/1826246/find-n-unique-integers-sum-up-to-zero-100-simple-solution\nhttps://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/1814346/find-minimum-in-rotated-sorted-array-binary-search-100-ceasy-solution\nhttps://leetcode.com/problems/is-subsequence/discuss/1811098/is-subsequence-100-c-easy-solution\nhttps://leetcode.com/problems/search-in-rotated-sorted-array/discuss/1808021/search-in-rotated-sorted-array-ologn-solution-simple-solution-binary-search\nhttps://leetcode.com/problems/check-if-number-is-a-sum-of-powers-of-three/discuss/1799853/check-if-number-is-a-sum-of-powers-of-three-100-easy-solution\nhttps://leetcode.com/problems/sequential-digits/discuss/1751815/sequential-digits-c-100-easy-solution\nhttps://leetcode.com/problems/binary-gap/discuss/1749101/binary-gap-100-c-simple-solution\nhttps://leetcode.com/problems/kth-largest-element-in-an-array/discuss/1730888/kth-largest-element-in-an-array-c-sorting-simple-solution\nhttps://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/1726527/queries-on-number-of-points-inside-a-circle-c-simple-mathematics\nhttps://leetcode.com/problems/integer-to-roman/discuss/1726042/integer-to-roman-c-easy-to-understand\nhttps://leetcode.com/problems/rings-and-rods/discuss/1724149/rings-and-rods-100-c-using-hashmap\nhttps://leetcode.com/problems/number-complement/discuss/1722669/number-compliment\nhttps://leetcode.com/problems/find-the-duplicate-number/discuss/1809351/find-the-duplicate-number-o1-space-binary-search-easy-solution\nhttps://leetcode.com/problems/smallest-string-with-a-given-numeric-value/discuss/1872424/Smallest-String-With-A-Given-Numeric-Value-oror-C%2B%2B-O(n)-oror-Simple-Solution-with-Explaination\nhttps://leetcode.com/problems/broken-calculator/discuss/1875269/Broken-Calculator-oror-C%2B%2B-100-O(n)-oror-Greedy-solution-with-Explanation-oror-Easy-Simple-Solution\nhttps://leetcode.com/problems/generate-parentheses/discuss/1875357/Generate-Parentheses-oror-C%2B%2B-recursive-Approach-with-explaination-oror-Easy-Approach
['Two Pointers', 'Greedy', 'C', 'Sorting']