Quant Memo
Coding/●●●●●

Fewest boats to carry everyone across

You have people with given weights. Each boat carries at most two people and a combined weight of at most limit. Every weight is at most limit, so everyone can be carried.

people = [3, 2, 2, 1], limit = 3
-> 3          # (3), (1,2), (2)

Return the minimum number of boats. Aim for O(nlogn)O(n \log n), and justify why pairing the heaviest with the lightest is optimal.

Show a hint

Sort the weights. The heaviest person must ride on some boat no matter what. Who is the best possible cabin-mate for them?

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions