Data Structures & AlgorithmsVery hardProduct company OA

A circular queue of capacity 5 starts empty and runs this sequence in order: enqueue(7), enqueue(2), dequeue(), enqueue(5), dequeue(), enqueue(5), enqueue(1), enqueue(3). What are its final contents, front to rear (dequeue on empty is a no-op)?

  1. A. empty
  2. B. 3, 1, 5, 5
  3. C. 5, 5, 1, 3
  4. D. 5, 5, 1

Correct answer: C. 5, 5, 1, 3

A circular queue wraps the rear index modulo its capacity instead of shifting elements on dequeue; tracing front/rear/size through all 8 operations in order leaves [5, 5, 1, 3] from front to rear.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic