Number of Students Unable to Eat Lunch
Students wait in a queue and each accepts only sandwich type 0 or 1. students[0] is the front; sandwiches[0] is the stack top. A matching front student takes…
Students wait in a queue and each accepts only sandwich type 0 or 1. students[0] is the front; sandwiches[0] is the stack top. A matching front student takes the top sandwich and leaves. Otherwise that student moves to the rear while the sandwich stays. Stop when everyone eats or no remaining student wants the top item. Return the number left; do not skip unwanted sandwiches.
The two arrays have equal length n, 1 <= n <= 100. Elements are strict integers 0 or 1, not Booleans or fractions. Return an integer in [0,n]. The inputs need not be mutated. Teaching traces contain at most 12 students; coding retains n <= 100.
Example 1: input students = [1,1,1,0], sandwiches = [1,0,0,0]; output 2. A type-1 student eats, rotation reaches the only type-0 student, and the next type-0 sandwich blocks the two remaining students.
Example 2: input students = [0,1,0], sandwiches = [0,1,0]; output 0. Every front student accepts the current top without rotation.
Category: Queues. Topic: queue. Difficulty: Medium. Patterns: linear-scan.