Data Structures & AlgorithmsHardGATE CS · DSA
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: deq, enq(51), enq(67), enq(83), enq(86), deq, enq(90), enq(60), enq(41), deq, enq(77), deq, enq(11), enq(26). 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 = 2, rear = 3, count = 1
- B. front = 3, rear = 2, count = 6
- C. front = 3, rear = 3, count = 7
- D. front = 4, rear = 2, count = 5
Correct answer: B. front = 3, rear = 2, count = 6
Simulating (outputs E 51 67 83 F): 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
- A fixed sliding window of length 5 moves over "programmingisfun". What is the maximum number of vowels (a, e, i, o, u) inside any window?
- How many contiguous subarrays of [4, 2, 2, 6, 4, 1, 5] have bitwise XOR equal to 6? (Prefix XORs with a frequency map: add freq[px ^ 6] at…
- What is the minimum number of characters that must be APPENDED to the end of "abacdcab" to make it a palindrome? (Find the longest…
- For [7, 3, 5, 3, 7, 2, 5], definition A returns the element whose FIRST occurrence is earliest among all repeating elements; definition B…
- nums1 = [2, 5, 8, 0, 0, 0] (3 real values plus 3 buffer slots) and nums2 = [3, 6, 9] are merged in place by filling nums1 from the BACK…
- What is the sum of the minimum value of every contiguous window of length 3 in the array [4, 2, 12, 11, -5, 3, 7]?