Opening your workspace…
Workspace/Coding room
Opening your workspace…
At the beach camp, Vincent rolls his empty bowl against Hurley's ankle. Rain is dripping from the torn seats of Oceanic Flight 815 into a ring of buckets. Hurley has a pail to carry the water and a promise to keep. Between each pair of buckets a survivor is waiting with a cup and knows exactly how much water they were promised.
Hurley starts with an empty pail at any bucket. At bucket i he adds all rain[i] cups to his pail, which holds any amount. On the clockwise walk to the next bucket he must hand over toll[i] cups. The last bucket leads back to bucket 0. How many starting buckets let Hurley walk the ring once, keep every promise, and bring Vincent at least one cup?
[1,4,0,3], [2,1,2,1]Output2Starting at bucket 1 leaves 3, 1, 3 and 2 cups after the four handouts. Bucket 3 also works. At buckets 0 and 2 Hurley cannot fill the first order.
[3,0,2], [1,2,2]Output0Hurley promised all five cups. Even if he makes it around the ring, Vincent's bowl stays empty.
Over two laps, keep the smallest prefix balance in each one-lap window.
function solve(rain, toll) { // 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.