Amazon Interview Question
Software Engineer / Developerssemaphores anyone to synchronize??/ what say
points to note
1. no. of attenders n guests m m>n(else restaurant is a flop !!)
divide m evenly to n... as in assign 1 to 1 then need be then 1 to 2
2. no. of chef n no. of orders m n<m use priority queue to extract order and assign equally to chef
3. people waiting
maybe semaphore is good here -- implement finite consumer producer problem in 1. and 2 .
We could delegate every task to an execution thread for example one manager, 10 servers, 5 cooks, 5 cleaners. Tables could be shared resource going through states that require attention of different threads - occupied, free, dirty etc. Similarly synchronize kitchen processes. All threads would relinquish control to the manager thread . Random thoughts but I think I would solve on these lines.
I think focus should be more on how to design data structures for reservations, assigning tables to waiters, etc
- NITW Guy October 31, 2008