Each boat carries at most 2 people with total weight <= limit. Find minimum number of boats.

Input: people=[1,2], limit=3 → Output: 1. Both can share a boat. Input: people=[3,2,2,1], limit=3 → Output: 3. (1,2),(2),(3) need 3 boats.

Sort people. Use two pointers: pair lightest with heaviest when possible.

public int numRescueBoats(int[] people, int limit) { Arrays.sort(people); int left = 0, right = people.length - 1, boats = 0; while (left <= right) { if (people[left] + people[right] <= limit) left++; right--; boats++; } return boats; }