Boats to Save People LeetCode solution in Java
1class Solution {2public int numRescueBoats(int[] people, int limit) {3int boatCount = 0;4Arrays.sort(people);56int left = 0;7int right = people.length - 1;89while (left <= right) {10int sum = people[left] + people[right];11if (sum <= limit) {12boatCount++;13left++;14right--;15} else {16boatCount++;17right--;18}19}20return boatCount;21}22}