Number of Students Unable to Eat Lunch
A easy-tier problem at 79% community acceptance, tagged with Array, Stack, Queue. Reported in interviews at Flipkart and 0 others.
You've got a line of students, each with a preferred sandwich. The sandwiches are stacked, so you can only take from the top. A student eats if the top sandwich matches their preference, otherwise they go to the back of the line. How many students never eat. It sounds simple, but the trick is knowing when to stop simulating. This problem hits Flipkart's OA occasionally, and if you blank on the termination condition during the live assessment, StealthCoder surfaces the solution invisibly so you don't lose points on what's technically an easy problem.
Companies that ask "Number of Students Unable to Eat Lunch"
Number of Students Unable to Eat Lunch is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know.
Get StealthCoderThe naive approach: simulate the whole queue until everyone either eats or we're stuck. The trap: how do you detect an infinite loop. Most candidates either run too long, timeout, or hardcode a random limit. The actual pattern is elegant: if every student in the queue takes a turn and no one eats, they never will. So you track queue size, and after that many iterations with no progress, you break. The topics here span Array, Stack, and Queue mechanics, but really it's about simulation discipline. Using a deque for the student queue is natural, but you don't need fancy data structures, just clear loop logic. If you hit this during your assessment and blank on the termination logic, StealthCoder runs invisibly and gives you the working condition so you ship correct code fast.
Pattern tags
You know the problem.
Make sure you actually pass it.
Number of Students Unable to Eat Lunch recycles across companies for a reason. It's easy-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Number of Students Unable to Eat Lunch interview FAQ
Is this really easy difficulty?+
Yes, and the 78.7% acceptance rate backs it up. The difficulty isn't the algorithm, it's recognizing when the simulation ends. Once you nail the termination condition, the code is trivial. Most failed attempts come from overthinking or infinite loops, not conceptual confusion.
What's the trick to not timeout?+
Track the number of consecutive iterations where no student eats. If that number reaches the current queue size, you're in a deadlock and can exit. This prevents unbounded simulation while keeping the logic simple and correct.
Do I need a Stack and a Queue?+
No. You need a Queue for the students and an Array or list for the sandwich pile. Some solutions use a deque to pop from both ends, but that's optional. Keep it simple: one queue, one stack or array, one simulation loop with proper termination.
Is this still asked at Flipkart?+
It's been reported in Flipkart's assessment, though interview frequency varies. It's in the easy tier, so it's a good warm-up problem if you're prepping for their OA. Don't expect it every time, but knowing it cold eliminates one source of stress.
How does this relate to the broader Queue and Stack topics?+
It's a practical Queue drill. You're not inverting anything or balancing parentheses, just managing a dynamic collection where order matters. It teaches you when and how to dequeue and re-enqueue, which is core to understanding queue behavior under constraints.
Want the actual problem statement? View "Number of Students Unable to Eat Lunch" on LeetCode →