short solution
Intuition\nIn the worst case scenario when weights of all people are close to limit we will have one boat for each of the people => so the number of boats in th
# Intuition\nIn the worst case scenario when weights of all people are close to limit we will have one boat for each of the people => so the number of boats in this case is size of people array.\n\nEvery iteration take the the greatest and the smallest weight. If in sum they are less or equal to limit, then we can put them in one boat => so the number of boats could be decreased by one.\n\n\n# Approach\nLet\'s sort people weights in asc order and every iteration extract last item - the most heavy, and check the weight of the first item.\n\nIf we can put two of these people together in the same boat => then we should extract first item from people array too and decrease number of boats.\n\nOtherwise if together they exceed the limit => number of boats shouldn\'t change.\n\n# Complexity\n- Time complexity:\nO(n log n)\n- Space complexity:\nO(n)\n\n# Code\n```\nfunction numRescueBoats(people: number[], limit: number): number {\n    people.sort((a, b) => a - b);\n    let min = people.length;\n\n    while(people.length > 0) {\n        const p1 = people.pop();\n        if (p1 + people[0] <= limit) {\n            const p2 = people.shift();\n            min--;\n        }\n    }\n\n    return min;\n};\n```
['TypeScript']