Opening your workspace…
Workspace/Coding room
Opening your workspace…
At the North Pole, the workshop door is buried in snow and the elves must carry the finished gift sacks to the waiting sleighs. Each sleigh can take at most two sacks, and their combined weight cannot exceed its limit. The elves want to use as few sleighs as possible so the reindeer can leave before the storm arrives. Given the sack weights and the sleigh limit, return the fewest sleighs needed.
[1,2,3,4,5], 5Output3Pair sacks 1 and 4, then 2 and 3. Sack 5 rides alone, so three sleighs are enough.
[4,4,2,2,2], 6Output3Each 4 can ride with a 2, and the remaining 2 rides alone.
Try pairing the heaviest remaining sack with the lightest.
function solve(weights, limit) { // Write your solution here. }
Tab inserts two spaces. Shift+Tab outdents. Use the arrow keys and Tab to choose a suggestion. Press Escape, then Tab, to leave the editor. Press Control or Command with apostrophe to run samples or with Enter to submit.