Bounded Producer–Consumer Queue
Reported by candidates from MakeMyTrip's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The MakeMyTrip OA reported in September 2026 looks like a easy queue sim, then one detail trips people up: what happens to a blocked producer when a consume frees a slot. It's a bounded producer-consumer queue, and the output has to match string for string. Two queues, one event loop, no real threads. If you've seen a ready queue plus a waiting queue before, you're fine. If you haven't, the resume rule is where wrong answers come from. StealthCoder is the safety net if you blank during the live OA, but the logic here is short enough to hold in your head.
The problem
Simulate a bounded FIFO task queue from a finite event stream. PRODUCE task enqueues the task and returns ENQUEUED task when capacity is available. If the ready queue is full, the producer joins a FIFO waiting queue and returns WAIT task. CONSUME returns IDLE when no task is ready; otherwise it removes the oldest ready task and returns CONSUMED task. After a successful consume, the oldest waiting producer immediately resumes and its task enters the ready queue; append RESUMED task to that consume result. Function simulateBoundedQueue(capacity: int, events: String[]) → String[] Examples Example 1 capacity = 2 events = ["PRODUCE a","PRODUCE b","PRODUCE c","CONSUME","CONSUME","CONSUME"] return = ["ENQUEUED a","ENQUEUED b","WAIT c","CONSUMED a RESUMED c","CONSUMED b","CONSUMED c"] c waits until consuming a frees one ready slot. Example 2 capacity = 1 events = ["CONSUME","PRODUCE x","PRODUCE y","CONSUME"] return = ["IDLE","ENQUEUED x","WAIT y","CONSUMED x RESUMED y"] The first consume is idle; the final consume resumes y. Constraints 1 <= capacity <= 100000 0 <= events.length <= 200000 Each event is exactly PRODUCE task or CONSUME. Task tokens are nonempty ASCII strings without whitespace and are treated as independent tasks.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Keep two FIFO queues: a ready queue capped at capacity and a waiting queue of blocked producers. PRODUCE: if ready size is below capacity, enqueue and return ENQUEUED task. Otherwise push to waiting and return WAIT task. CONSUME: if ready is empty, return IDLE. Otherwise pop the oldest, build CONSUMED task, then if waiting is nonempty, pop its front, push that task into ready, and append RESUMED task to the same result string. The pitfall is treating resume as its own output line, or resuming before the pop. Another trap is using a list with remove(0) in a language where that's O(n). With 200000 events, use a deque or head indexes. Each event is O(1), so the whole thing is O(n). If you freeze mid-OA, StealthCoder can give you the two-queue skeleton so you only check the string formatting.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Bounded Producer–Consumer Queue 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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass MakeMyTrip's OA.
MakeMyTrip reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Bounded Producer–Consumer Queue FAQ
How hard is the MakeMyTrip bounded queue problem really?+
Easy to medium. There's no clever algorithm. It's a careful simulation with two queues. Most failures come from output formatting and the resume step, not from complexity. If you can write a deque-based loop cleanly, you'll finish quickly.
What's the trick to the resume rule?+
Resume happens inside the consume result, after the pop. Pop the oldest ready task, free the slot, then move the oldest waiting producer into ready and append ' RESUMED task' to the same string. It's one output entry per event, never two.
Which data structures should I use?+
Two deques, or arrays with head pointers. One holds ready tasks, one holds waiting producers. Don't use a list with front removal, since 200000 events can make that slow. Every operation should be O(1) amortized.
What edge cases should I test before submitting?+
Consume on an empty queue returns IDLE. Multiple waiting producers resume one per consume, in order. Capacity 1 with several produces in a row. An empty events array returns an empty list. Duplicate task names are independent, so don't use a set.
How do I prepare for this in 48 hours?+
Write the two-queue simulation from scratch once, then trace both examples by hand. Practice a couple of other event-stream simulations like LRU-style or ticket-queue problems. The skill is translating rules into state transitions without skipping a clause.