WebNov 18, 2024 · View sourin_bruh's solution of Boats to Save People on LeetCode, the world's largest programming community. Problem List Premium RegisterorSign in Boats … Web881. 救生艇 - 给定数组 people 。people[i]表示第 i 个人的体重 ,船的数量不限,每艘船可以承载的最大重量为 limit。 每艘船最多可同时载两人,但条件是这些人的重量之和最多为 limit。 返回 承载所有人所需的最小船数 。
Leetcode- 881.Boats to Save People Medium, Python - YouTube
WebEach boat can carry atmost two people and the sum of the weigths of them should be less or atmost the limit provided. We need to find the minimum number of boats that can save each one of them. Approach 1: The first solution that comes up is obviously brute force: step 1: check for pairs which can go in a boot together without breaking the ... react cpap masks
[Hindi] 881. Boats to Save People Leetcode Medium Greedy
WebJan 13, 2024 · If people[beg] + people[end] <= limit, then we can put these two persons in one boat, so we move beg to the right, end to the left and increment ans by one. In opposite case it means, that person with smallest weight and with biggest weight so far can not be put in one boat, so, we need to decrease weight: movint end pointer one step to the left. WebJan 13, 2024 · LeetCode — Boats to Save People. Problem Description: The i -th person has a weight people [i], and each boat can carry a maximum weight of limit. Each boat carries at most 2 people at the same time, provided the sum of the weight of those people is at most limit. Return the minimum number of boats to carry every given person. WebThe given code solves the problem of finding the minimum number of boats required to rescue a group of people from a sinking ship. Each boat has a weight limit, and each person has a specific weight. The goal is to load the people onto the boats in such a way that no boat exceeds its weight limit, and the minimum number of boats are used. how to start chestnut seeds