Opening your workspace…
Workspace/Coding room
Opening your workspace…
Help Jim fit as many of Dwight’s staplers as he can in one tray of Jell-O. The tray is one stapler wide, so Jim lines them up end to end. He needs at least 1 cm of Jell-O between neighboring staplers and at each end of the row. Given the tray’s inside length and the length of each available stapler, return the largest number he can hide.
24, [12,6,8,6]Output3The 6, 8, and 6 cm staplers use 20 cm. Four 1 cm gaps fill the tray exactly. The remaining stapler cannot fit.
22, [10,10,10]Output1One stapler needs 12 cm including the ends. Two need 23 cm once Jim leaves Jell-O between them, so the tray is 1 cm short.
Reserve the first gap, then add the shortest staplers with one gap after each.
function solve(trayLength, staplerLengths) { // 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.