Skip to main content
All Questions

N people queue for seats: each takes the wanted seat if it is free, otherwise wants the next seat number and rejoins the back of the queue. Return everyone's final seat.

Unlock detailed company stats for this questionUpgrade
N people stand in a queue, and person i wants seat arr[i], a value from 1 to N. People are taken in queue order. If the wanted seat is free, the person sits there. Otherwise the person increases the wanted seat number by one and moves to the back of the queue. Seat numbers above N are allowed. Return the seat each person ends up in, with a solution that stays fast for large N.

Community answers

No answers contributed by the community yet.

Related courses

Course

Behavioral Interviews: A Practical Guide for Engineers

Get offers at the level you deserve. Prep for senior+ behavioral interviews at FAANG and Tier-1 companies. Made with staff and principal engineers from Meta, Netflix, Google, and more. Avoid downleveling, elevate past projects, and stop sounding like a robot.

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.