649. Count of Students Unable to Eat Lunch

MediumStackStackQueueSimulation

Students form a queue and sandwiches form a stack, each preference being 0 or 1. The front student takes the top sandwich if it matches, otherwise moves to the back. This continues until no remaining student wants the top sandwich. Return the number of students who cannot eat. The input is JSON {students, sandwiches}.

Input: JSON {students, sandwiches}.

Output: Integer — the count of students unable to eat.

Examples

Example 1
Input: {"students":[1,1,0,0],"sandwiches":[0,1,0,1]}
Output: 0
Explanation: Everyone eats.
Example 2
Input: {"students":[1,1,1,0,0,1],"sandwiches":[1,0,0,0,1,1]}
Output: 3
Explanation: Three remain stuck.
Example 3
Input: {"students":[0],"sandwiches":[0]}
Output: 0
Explanation: Single match.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →