Opening your workspace…
Workspace/Coding room
Opening your workspace…
At the Mad Hatter’s tea party, cups are passed along a row of guests. Guest 0 takes the first cup. Each guest drinks one sip. If there’s tea left, they pass the cup to the next guest. If it’s empty, they set it aside and the next guest takes a fresh cup. After the last guest, it’s guest 0’s turn again. Given the number of sips in each cup, return the number of the guest who takes the first sip from each one.
3, [2,1,4,3]Output[0,2,0,1]The first cup starts at guest 0. After two sips the next cup begins at guest 2. One sip later it is guest 0 again, and four sips later it is guest 1.
4, [1,1,1,1]Output[0,1,2,3]Each cup lasts for one sip, so each guest receives the next cup in turn.
The total number of earlier sips determines the next guest modulo the number of guests.
function solve(guests, sips) { // 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.