Tap here to switch tabs
Problem
Submissions

Problem: Number of Students Unable to Eat Lunch

med
30 min
Try to solve the Number of Students Unable to Eat Lunch problem.

Statement

The school cafeteria serves circular and square sandwiches, represented by 00 and 11 respectively. All students stand in a queue, with each student possessing a preference for either a circular (00) or square (11) sandwich.

The sandwiches are arranged in a stack. At each step, if the student at the front of the queue prefers the sandwich on top of the stack, they take it and leave the queue. Otherwise, they leave the sandwich on the stack and move to the end of the queue.

This process repeats until none of the students remaining in the queue want to take the top sandwich, making it impossible for anyone to proceed.

Return the number of students who are unable to eat.

Constraints:

  • 1≤1 \le students.length, sandwiches.length ≤100\le 100

  • students.length ==== sandwiches.length

  • sandwiches[i] is either 00 or 11.

  • students[i] is either 00 or 11.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Students Unable to Eat Lunch

med
30 min
Try to solve the Number of Students Unable to Eat Lunch problem.

Statement

The school cafeteria serves circular and square sandwiches, represented by 00 and 11 respectively. All students stand in a queue, with each student possessing a preference for either a circular (00) or square (11) sandwich.

The sandwiches are arranged in a stack. At each step, if the student at the front of the queue prefers the sandwich on top of the stack, they take it and leave the queue. Otherwise, they leave the sandwich on the stack and move to the end of the queue.

This process repeats until none of the students remaining in the queue want to take the top sandwich, making it impossible for anyone to proceed.

Return the number of students who are unable to eat.

Constraints:

  • 1≤1 \le students.length, sandwiches.length ≤100\le 100

  • students.length ==== sandwiches.length

  • sandwiches[i] is either 00 or 11.

  • students[i] is either 00 or 11.