Number of Students Unable to Eat Lunch

Easy · Queue & Deque · about 10 minutes

Asked at Microsoft, Amazon, Bloomberg, Google, Meta.

Sandwiches are circular (0) or square (1), stacked in sandwiches (index 0 on top). Students queue with preferences students. The front student takes the top sandwich if it matches their preference; otherwise they go to the back of the queue. This stops when no student in the queue wants the top sandwich. Return the number of students unable to eat.