As reported: Rubrik, two loops. Senior software engineer (Bengaluru, October 2024), round 2 — concurrency: implement a queue in a buffer, then two queues in the same buffer while minimising wasted space. Another Rubrik interview (2025): design two queues using one array of fixed size
N; extra bookkeeping structures are allowed, but the elements themselves must be stored in the array, and space freed by popped elements must be reused.
Part 1. Implement a FIFO queue that stores its elements in a fixed-size buffer of N slots.
Part 2. Store two independent queues in the same buffer of N slots:
push(q, x)andpop(q)forq ∈ {1, 2};- elements live in the buffer; you may keep extra bookkeeping outside it;
- space released by pops in either queue must be reusable by both — wasted space should be small, so
pushfails only when the buffer is (nearly) full.
Clarifications
- Discuss the trade-off between per-element bookkeeping and wasted space.