Data Structures & AlgorithmsVery hardTCS NQT · Infosys pattern
A circular queue of capacity 4 starts empty and runs this sequence in order: enqueue(2), enqueue(6), dequeue(), dequeue(), enqueue(1), dequeue(), enqueue(8), enqueue(3). What are its final contents, front to rear (dequeue on empty is a no-op)?
- A. 8, 3
- B. 3, 8
- C. empty
- D. 8
Correct answer: A. 8, 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 [8, 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
- Keys 13, 28, 91, 42, 33 are inserted via linear probing (h(k) = k mod 7, probe by +1 on collision) into an initially empty table of size 7…
- Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the…
- Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the…
- Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the…
- A circular queue of capacity 4 starts empty and runs this sequence in order: enqueue(8), enqueue(2), enqueue(5), dequeue(), enqueue(1)…
- Binary search for first/last occurrence runs on the sorted array [1, 3, 7, 9, 11, 13, 15, 15, 16, 17, 18] for target 15. What (first…