Opening your workspace…
Workspace/Coding room
Opening your workspace…
At the moon fair, a keeper has found a school of tiny whales swimming in a puddle. Each whale weighs a little, and the keeper's enchanted coat pocket can hold at most a certain total weight. The keeper may choose which whales to scoop up, but cannot split one. How many whales can be carried away in the pocket?
[4,1,3,2], 6Output3Take the whales weighing 1, 2, and 3. They weigh 6 together, and no four whales fit.
[5,8,2], 4Output1Only the 2-weight whale fits in the pocket.
Choose the lightest whales first.
function solve(weights, capacity) { // 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.