Cups on the Counter
Customers wait in a line, and line[i] is the drink wanted by the customer at position i, with position 0 at the front. Ready drinks stand in a stack on the counter, and cups[0] is the top cup.
Repeat: if the customer at the front wants the top cup, they take it and leave; otherwise they go to the back of the line. Stop when the line is empty, the cups run out, or nobody in the line wants the top cup. Return how many customers are still waiting.
Example 1
The first customer steps back, the mocha customer takes the mocha, and the two tea customers take the two teas.
Example 2
After two customers are served, the top cup is a latte and the last customer wants tea.
Constraints
0 <= len(line) <= 1000 <= len(cups) <= 100- drinks are lowercase words of 3 to 5 letters
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.