DescriptionQ180
Q180FWASIC interview problem
Implement and verify a bounded queue
TechniquesPythonCircular bufferQueueInvariants
DifficultyMedium
TopicData Structures
LanguagePython
Requirements4 checkpoints
01
Problem
Implement a fixed-capacity FIFO with O(1) push, pop, and peek, then briefly explain how you would verify its boundary and wraparound behavior.
Example input and output
Use this case to check your interpretationInput
capacity=3; push(10), push(20), push(30), push(99), pop(), push(40)Output
push(99) reports overflow and changes no state; pop returns 10; final queue is [20, 30, 40]Explanation
The failed overflow leaves the full queue intact, then the final push wraps the circular tail into the slot cleared by pop.
02
Requirements (4)
- Reject nonpositive capacity, overflow, and pop or peek underflow.
- Use a circular array with explicit head, tail, and size state.
- Clear a popped slot so the queue does not retain stale object references.
- Describe directed wraparound checks and a seeded randomized comparison against collections.deque.
