585. Students Unable to Eat Lunch

EasyStackQueueSimulation

Students stand in a queue and sandwiches are in a stack, each being 0 or 1. The student at the front takes the top sandwich if it matches their preference, otherwise goes to the back of the queue. This repeats until no remaining student wants the top sandwich. Return the number of students unable to eat. The input is JSON {students, sandwiches}.

Input: JSON {students, sandwiches}.

Output: Integer — the count of students who cannot eat.

Examples

Example 1
Input: {"students":[1,1,0,0],"sandwiches":[0,1,0,1]}
Output: 0
Explanation: Every student eventually eats.
Example 2
Input: {"students":[1,1,1,0,0,1],"sandwiches":[1,0,0,0,1,1]}
Output: 3
Explanation: Three students remain.
Example 3
Input: {"students":[0],"sandwiches":[0]}
Output: 0
Explanation: The single student eats.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →