0 and 1. The trays are stacked, with trays[0] on top. A line stands at the counter, line[0] at the front, and each person wants one particular kind of tray. There are exactly as many trays as people.
Serving works like this: if the person at the front wants the kind on top of the stack, they take that tray and leave. Otherwise they go to the back of the line. Nobody may take a tray other than the top one.
Serving stops once nobody left in line wants the top tray. Return how many people go without lunch.line=[0, 1, 1], trays=[1, 0, 1] → 0
The first person wants 0 but the top is 1, so they move to the back: [1, 1, 0]. The next one takes the 1, leaving [1, 0] and trays [0, 1]. The front 1 goes to the back again, the 0 is taken, then the last 1. Nobody is left hungry: 0.
line=[0, 0, 1, 0], trays=[1, 1, 0, 0] → 3
The only person who wants 1 takes the top tray. The next tray is 1 again, but the three people left all want 0, so none of them eats. The answer is 3.
line=[0, 1, 1], trays=[1, 0, 1]
0
Run checks the first 3 tests in your browser. Submit checks all 88 tests on the server, hidden ones included.