Data Structures & AlgorithmsHardIBM · Deloitte pattern
A circular queue of capacity 4 starts empty and runs this sequence in order: enqueue(3), enqueue(6), enqueue(4), enqueue(7), dequeue(), enqueue(5), dequeue(). What are its final contents, front to rear (dequeue on empty is a no-op)?
- A. empty
- B. 5, 7, 4
- C. 4, 7
- D. 4, 7, 5
Correct answer: D. 4, 7, 5
A circular queue wraps the rear index modulo its capacity instead of shifting elements on dequeue; tracing front/rear/size through all 7 operations in order leaves [4, 7, 5] 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
- The Boyer–Moore majority vote algorithm (candidate/counter, no verification pass) runs on [7, 5, 2, 5, 5, 5, 2, 7]. What candidate and…
- What does this loop-counting code print? (Python) python n, c = 45, 0 i = 1 while i < n: j = i while j < n: c += 1 j = 2 i += 1 print(c)
- Array [83, 87, 90, 43, 45, 48, 62, 75, 82] is a sorted array rotated at pivot 6. Using the standard O(log n) rotated-array binary search…
- Using a sliding window of fixed size with a character-frequency count, how many substrings of "AAABAAABCB" are anagrams of "BA"?
- Heights [6, 3, 1, 5, 9, 8, 9, 6, 4] represent vertical lines at each index. What is the maximum water area (min(height) × horizontal…
- Kadane's algorithm runs on the array [-9, 1, 7, 5, 7, -3, 0, -7, 1] to find the maximum sum of a contiguous subarray. What sum does it…