Easy | Greedy Strategy | Filling the boat effectively | 2 Pointer approach | beat 100% | Follow step
\n\n# Code\n\nclass Solution {\npublic:\n    // Greedy Solution -> how to fill boat of size 2 effectively, so that we can achieve maximum number of boats.\n    
\n\n# Code\n```\nclass Solution {\npublic:\n    // Greedy Solution -> how to fill boat of size 2 effectively, so that we can achieve maximum number of boats.\n    int numRescueBoats(vector<int>& people, int limit) {\n\n        sort(people.begin(),people.end());\n\n        int n = people.size();\n        \n        int low = 0, high = n-1;\n        int cnt = 0;\n\n        while(low < high)\n        {\n            int sum = people[low] + people[high];\n\n            if(sum <= limit)\n            {\n                cnt++;\n                low++;\n                high--;\n            }\n            else\n            {\n                cnt++;\n                high--;\n            }\n        }\n\n        if(low == high)\n        {\n            cnt++;\n        }\n\n        return cnt;\n  \n    }\n};\n```
['Array', 'Two Pointers', 'Greedy', 'C++']