Data Structures & AlgorithmsHardProduct placement · Amazon/Microsoft
A circular queue in an array of size 5 keeps one slot empty to tell full from empty (front = rear means empty; (rear + 1) mod 5 = front means full). Starting empty, it runs: enq(94), enq(89), deq, enq(32), enq(55), enq(72), enq(58), deq, deq, deq, deq, enq(72), enq(42), enq(93). 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 = 0, count = 2
- B. front = 0, rear = 3, count = 3
- C. front = 0, rear = 4, count = 4
- D. front = 1, rear = 3, count = 2
Correct answer: B. front = 0, rear = 3, count = 3
Simulating (outputs 94 F 89 32 55 72): with N − 1 = 4 usable slots, rejections happen at 4 elements. Count = (rear − front) mod 5 = 3.
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
- Insertion sort (ascending; shift larger elements right, one key comparison per inner-loop test, the loop stops at the first element ≤ the…
- What is the minimum number of swaps (of any two elements) needed to bring all the 1s of [1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1] together into…
- Can a string become a palindrome by deleting at most one character? Two pointers try skipping either side on the first mismatch. What is…
- Items K, L, M, N, O are pushed onto an empty stack in this order, and a pop may happen at any time. Which pop order is NOT possible?
- Remove the n-th node from the END of a linked list in one pass, using a dummy node and a gap of n between two pointers. What is printed?…
- In a singly linked list with only a head pointer, which operation CANNOT be done in O(1) time?