The Design Bounded Blocking Queue interview question is a thread-synchronization challenge. You need to implement a queue with a maximum capacity. If a thread tries to add an item to a full queue (enqueue), it must block (wait) until space becomes available. Similarly, if a thread tries to remove an item from an empty queue (dequeue), it must block until an item is added.
Companies like Tesla and LinkedIn use the Design Bounded Blocking Queue coding problem to evaluate your knowledge of Concurrency and multi-threading. It tests your ability to use synchronization primitives like Mutexes, Semaphores, or Condition Variables. It's a fundamental test of handling "Race Conditions" and "Deadlocks."
This problem uses the Producer-Consumer Pattern with Condition Variables.
notFull and notEmpty.enqueue: While queue.size() == capacity, wait on notFull. After adding, signal notEmpty.dequeue: While queue.size() == 0, wait on notEmpty. After removing, signal notFull.Capacity = 2.
enqueue(1). Success.enqueue(2). Success.enqueue(3). Queue is full. Thread 3 blocks.dequeue(). Returns 1. Queue now has space.enqueue(3).while(true) loop without wait() calls, which consumes 100% CPU.if instead of while: Failing to re-check the condition after being signaled (Spurious Wakeups).Understand the difference between notify() and notifyAll() (or signal() and broadcast()). In this problem, signal() is usually sufficient because you only need to wake up one waiting producer/consumer, but broadcast() is safer.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Building H2O | Medium | Solve | |
| Fizz Buzz Multithreaded | Medium | Solve | |
| Print Zero Even Odd | Medium | Solve | |
| The Dining Philosophers | Medium | Solve | |
| Print in Order | Easy | Solve |