i-th hiker weighs weights[i]. There are as many rafts as you like, but each raft carries at most two people, and their combined weight must not exceed capacity.
Return the smallest number of rafts needed to get everyone across.weights=[70, 50, 80, 40], capacity=120 → 2
80 and 40 fit together (120), and so do 70 and 50 (120): two rafts are enough.
weights=[60, 90, 30, 100], capacity=100 → 3
100 and 90 each need a raft of their own. 60 and 30 weigh 90 together and share one. Three rafts in total.
weights=[5, 5, 5], capacity=10 → 2
A raft holds at most two people, so the third one needs a raft of their own.
weights=[70, 50, 80, 40], capacity=120
2
Run checks the first 3 tests in your browser. Submit checks all 92 tests on the server, hidden ones included.