Constant-Time Restaurant Waiting List
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The data structure is the whole question here. This Bloomberg OA, reported in March 2020, asks you to run a restaurant waiting list where add, seat, and move all have to be O(1). Customer IDs are unique, and move swaps a customer with the one right ahead of them. A plain array or list fails the moment you need to find someone mid-queue. The answer is a doubly linked list plus a hash map from ID to node. If you blank on the wiring under pressure, StealthCoder is the invisible safety net running during the live OA.
The problem
Maintain a queue of unique waiting customer IDs: add: append customers[i], return null. seat: remove and return the first customer. move: swap the named customer with its immediate predecessor, or do nothing if already first; return null. Implement every operation in O(1). Function runRestaurantQueue(operations: String[], customers: String[]) → String[] Examples Example 1 operations = ["add","add","add","move","seat","seat"] customers = ["A","B","C","C","",""] return = ["null","null","null","null","A","C"] Moving C produces A,C,B; seats then remove A and C. Constraints At most 10^5 valid operations.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is pairing two structures. Keep a doubly linked list for order and a hash map from customer ID to node. Add appends at the tail and stores the node in the map. Seat pops the head, deletes it from the map, and returns the ID. Move looks up the node in O(1), checks whether it has a predecessor, then swaps the two. The easiest way to swap is to exchange the stored IDs and update both map entries, which avoids pointer surgery. Pitfalls: forgetting to update the map after a swap, mishandling head and tail with dummy sentinels, and returning the string "null" instead of a real null. The output array expects "null" strings for add and move. Test with a single customer and with moving the second person. If the pointer logic slips mid-OA, StealthCoder can hand you a clean version while you keep control.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Constant-Time Restaurant Waiting List cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Bloomberg's OA.
Bloomberg reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Constant-Time Restaurant Waiting List FAQ
What's the trick to getting O(1) for every operation?+
Use a doubly linked list for the order and a hash map from customer ID to list node. The map gives instant lookup for move, and the list gives instant removal from the front and append at the back. Neither structure alone is enough.
How hard is the Bloomberg restaurant queue problem really?+
Medium. The idea is short, but the implementation has edge cases: moving the head, moving the tail, and seating the last person. Candidates who know the linked list plus hash map combo finish fast. Candidates who reach for an array usually time out.
Why can't I just use a list or deque?+
Finding a specific customer in a list is O(n), and swapping inside a deque is no better. With up to 10^5 operations, that scan adds up and breaks the O(1) requirement. You need direct access to the node by ID.
What should I return for add and move?+
The examples show the string "null" in the output array for add and move. Seat returns the customer ID that was removed. Match that format exactly, or the output comparison will fail even if your logic is right.
How do I prepare for this in 48 hours?+
Write a doubly linked list with sentinel head and tail nodes from scratch, then add the hash map. Practice the swap by exchanging IDs and updating both map entries. Run the sample by hand, then test moving the first and last customers.