Leetcode Problem 1700. Number of Students Unable to Eat Lunch
1700. Number of Students Unable to Eat Lunch
Leetcode Solutions
Queue Simulation
Initialize a queue with all students' preferences.
Initialize a counter to keep track of consecutive students who cannot take the sandwich.
Iterate while the queue is not empty and the counter is less than the queue size.
a. Check if the student at the front of the queue prefers the sandwich on top of the stack.
b. If they do, dequeue the student and remove the sandwich from the stack.
c. If not, dequeue the student and enqueue them at the back, and increment the counter.
If the counter equals the queue size, break the loop as no more students can eat.