Opening your workspace…
Workspace/Coding room
Opening your workspace…
At the Pokémon Day Care, Snorlax is asleep across the nursery door. Outside, a row of hungry Pichu are waiting for their bedtime berries. You can slip a tray through the gap under Snorlax’s paw, but if he feels the same weight twice in a row, he’ll roll over and squash the gap shut.
Each Pichu wants a certain number of berries. Load each tray with exactly enough to feed the next one or more Pichu in line. All the berries weigh the same, and each tray holds at most capacity berries. What is the fewest trays you can send to feed everyone in order? Return -1 if you can’t finish.
[2,1,1,2], 4Output2Give the first three Pichu 4 berries between them, then send 2 for the last Pichu. All 6 berries won’t fit on one tray.
[1,1,1,1,2], 3Output3Filling the first tray with 3 leaves shares of 1 and 2. Instead, send trays carrying 2, 1, and 3 berries. Two trays would have to carry 3 each, which would wake Snorlax.
At each division keep the two cheapest prefixes with distinct last tray totals.
function solve(appetites, 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.