Number of Students Unable to Eat Lunch

Students are queued by preference and sandwiches are served in fixed order. Return how many students are unable to eat lunch. Pattern focus: Queue Simulation. Rotate the queue until the current sandwich can be served, otherwise stop when no progress is possible.

Input Format

students = preferences queue, sandwiches = sandwich stack order

Output Format

number of students unable to eat

Constraints

  • 1 <= input size <= 10^5
  • -10^9 <= numeric values <= 10^9
  • students, sandwiches must satisfy the format described in inputFormat.

Examples

Example 1:

Input:

students = [1,1,0,0]
sandwiches = [0,1,0,1]

Output:

0

Explanation:

All students can eventually take a sandwich they like.

Example 2:

Input:

students = [1,1,1,0,0,1]
sandwiches = [1,0,0,0,1,1]

Output:

3

Explanation:

Three students remain without a sandwich they like.

Loading...
Number of Students Unable to Eat Lunch