Number of Students Unable to Eat Lunch
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A cafeteria serves two kinds of sandwiches, labeled 0 and 1. The sandwiches sit in a stack where sandwiches[0] is on top, and the students wait in a queue where students[0] is at the front. Each student wants one kind.
Repeatedly, the front student looks at the top sandwich: if it is their kind they take it and leave the line; otherwise they move to the back of the queue. This continues until no student in the queue wants the top sandwich.
Return the number of students left without lunch.
Examples
Constraints
- 1 <= students.length == sandwiches.length <= 100
- students[i] is 0 or 1
- sandwiches[i] is 0 or 1
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.