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)?
- A. empty
- B. 3, 1, 5, 5
- C. 5, 5, 1, 3
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the postfix (Reverse Polish) form of the infix expression "f + d h -(i + e)", built with the standard stack-based conversion (^…
- Keys 88, 61, 14, 52, 18 are inserted via linear probing (h(k) = k mod 7, probe by +1 on collision) into an initially empty table of size 7…
- What is the postfix (Reverse Polish) form of the infix expression "j + g h -(i + c)", built with the standard stack-based conversion (^…
- The Dutch National Flag algorithm (single pass, three pointers low/mid/high) partitions [2, 2, 1, 0, 0, 0, 2, 2] (values 0, 1, 2 only) in…
- Two sorted linked lists [1 → 10 → 11 → 19 → 28] and [12 → 14 → 18 → 27 → 35] are merged with the standard O(n+m) two-pointer merge (always…
- Two sorted linked lists [3 → 14 → 35 → 39] and [9 → 20 → 21 → 27 → 34] are merged with the standard O(n+m) two-pointer merge (always take…