Boats to Save People LeetCode solution in C++
1// ��������Please upvote if it helps ��������2class Solution {3public:4int numRescueBoats(vector<int> &people, int limit) {5// sort vector6sort(people.begin(), people.end());78int i = 0, j = people.size() - 1, cnt = 0;910while (i <= j) {11// lightest person + heaviest person sum <= limit12// they can go together13if (people[i] + people[j] <= limit) {14++i;15--j;16}17// if sum is over the limit,18// heaviest will go alone.19else20--j;2122++cnt; // number of boats23}2425return cnt;26}27// for github repository link go to my profile.28};