Opening your workspace…
Workspace/Coding room
Opening your workspace…
When the tide cuts off the moonlit path, a keeper must guide a line of ember crabs to the safe cove. Each crab carries a little heat in its shell, and the keeper has one cooling blanket that can absorb only so much heat before it smokes. The crabs must stay in their original order, and the keeper can bring only one uninterrupted stretch of them. Given the heat of each crab’s shell and the blanket’s capacity, find the largest number of neighboring crabs the keeper can bring without exceeding that capacity. Return 0 if no crab can be brought.
[2,1,3,2,1], 6Output3The middle crabs carry heat 1, 3, and 2, totaling 6. Any four neighboring crabs exceed the blanket’s capacity.
[4,2,1,1,5], 4Output3The three crabs with heat 2, 1, and 1 fit exactly. The crab with heat 4 fits alone, but cannot be joined to a neighbor.
All heats are nonnegative, so removing a crab from the left can only cool the blanket.
function solve(heat, 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.