Boats To Save People
easy
1. You are given an array people where people[i] is the weight of the ith person. 2. You have infinite number of boats where each boat can carry a maximum weight of limit. 3. Each boat carries at most two people at the same time, provided the sum of the weight of those people is at most limit. 4. Return the minimum number of boats to carry every given person.
Constraints
1. 1 <= people.length <= 5 * 10^4 2. 1 <= people[i] <= limit <= 3 * 10^4
Format
Input
people = [3,2,2,1], limit = 3
Output
3 Explanation: 3 boats (1, 2), (2) and (3)
Example
Sample Input
4
3 2 2 1
3
Sample Output
3