โ† Intuit questions
CodingReported in a candidate post, Aug 2025

Implement a blocking queue and print odd/even numbers with threads

Filed under Intuit

Free read 2 of 3

Ask about capacity, number of producers and consumers, and whether interruption must be handled. The queue must be thread-safe and avoid busy waiting.

The question

Implement your own bounded blocking queue with put (blocks when full) and take (blocks when empty). Then write a program in which two threads print odd and even numbers alternately up to a limit.

Constraints

  • Queue capacity is fixed and positive
  • No busy waiting
  • Printing order must be 1, 2, 3, ... strictly alternating

Examples

Input
limit = 6
Output
Thread-odd:1, Thread-even:2, Thread-odd:3, Thread-even:4, Thread-odd:5, Thread-even:6
Why
The threads hand over control after each print.

Approach

  1. Ask about capacity, number of producers and consumers, and whether interruption must be handled. The queue must be thread-safe and avoid busy waiting.

Tips

  • What they are testing: Correct use of wait/notify or conditions, and avoiding lost wake-ups and busy waiting.
  • Common mistake: Using if instead of while around wait, or polling in a busy loop.

Related Intuit questions

Collected from public candidate posts and coding forums. Updated Nov 2026.