WebWe can start with the heaviest person and the lightest person, and try to pair them up. If their combined weight is less than or equal to the boat's weight limit, we add them to a boat and move the lightest person's pointer to the next person. Otherwise, we only add the heaviest person to a boat. Web/problems/boats-to-save-people/solution/shuang-zhi-zhen-jie-fa-by-xie-qing-3n-ms43/
⭐Explained Python 2 Pointers Solution - Boats to Save People - LeetCode
WebSep 30, 2024 · LeetCode 881. You are given an array people where people[i] is the weight of the i^th person, and an infinite number of boats where each boat can carry a … WebMar 24, 2024 · We have given weight of peoples Limit weight of boat & boats are available infinite But, we can only put Minimum of 1 person & Maximum of 2 person. Let's take one example, inorder to understand the problem:-. Input: people = [7,9,3,2,8,6,4,5], limit = 10. Output: 5. Okay so let's see what the very Brute-Force approach comes in your mind … crypto investment course
[Python] two pointers solution, explained - Boats to Save People - LeetCode
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. WebMar 24, 2024 · Boats to Save People simple solution Sahil_Kushwaha 8 Mar 24, 2024 def numRescueBoats(self, people: List[int], limit: int) -> int: n=len(people) people.sort() i=0 … WebMar 24, 2024 · Boats to Save People ⭐Explained Python 2 Pointers Solution anCoderr 762 Mar 24, 2024 OBSERVATIONS: Lets take an example: People = [1, 1, 2, 3, 9, 10, 11, 12] and Limit = 12 Since we want to minimise the number of boats used, we must try to form pair of largest and smallest numbers to fit them into one boat if possible. cryptologic company