β back to unit
Challenge
# puzzle gauntlet advanced
The Boat for Two
The rescue boats each hold TWO people at most, and combined weight can't pass the limit. Fewest boats wins! π€
You get everyone's weights (nobody exceeds the limit alone). Print the minimum number of boats. Clever pairing: sort, then try to buddy the heaviest with the lightest.
Example:
Input: weights = [70, 50, 80, 50], limit = 120
Output: 3
Sorted: [50, 50, 70, 80]. Lightest (50) + heaviest (80) = 130 > 120, so 80 boards alone (1 boat). Lightest (50) + next heaviest (70) = 120 β€ 120, so they pair (1 boat). The remaining 50 boards alone (1 boat) β 3 boats total.
π‘ need a hint?
pg-boat-for-two.pyπ given lines are locked β write your code in between
loading...