Data Structures & AlgorithmsHardTCS Digital · Infosys SP
A circular queue in an array of size 7 keeps one slot empty to tell full from empty (front = rear means empty; (rear + 1) mod 7 = front means full). Starting empty, it runs: enq(69), enq(94), enq(36), enq(69), enq(70), deq, enq(56), enq(66), enq(77), enq(95), deq, enq(80), deq, enq(88). A rejected enqueue prints F, a dequeue from an empty queue prints E, and a successful dequeue prints its value. What are front, rear and the number of elements at the end?
- A. front = 3, rear = 2, count = 6
- B. front = 4, rear = 2, count = 5
- C. front = 2, rear = 3, count = 1
- D. front = 3, rear = 3, count = 7
Correct answer: A. front = 3, rear = 2, count = 6
Simulating (outputs 69 F F 94 36): with N − 1 = 6 usable slots, rejections happen at 6 elements. Count = (rear − front) mod 7 = 6.
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
- Count distinct values in every window of size k with a frequency map. What is printed? python from collections import Counter a, k = [4…
- What is the minimum number of stacks needed to evaluate a fully parenthesised infix expression directly (without converting it first)…
- Merge sort and quick sort are compared. Which statement is correct?
- Bars of width 1 have heights [7, 3, 3, 6, 1, 3, 7, 1, 1]. How many units of rain water are trapped between them (two-pointer method with…
- Bubble sort (ascending; each pass compares adjacent pairs left to right and swaps if out of order) is applied to [49, 52, 21, 37, 35, 19…
- Z-array: z[i] is the length of the longest common prefix of s and s[i:], with z[0] defined as 0. What is printed? python s = "aaaaabaaa" z…