Data Structures & AlgorithmsHardGoldman Sachs OA · LeetCode medium-hard
A circular queue of capacity 4 starts empty and runs this sequence in order: enqueue(8), enqueue(2), enqueue(5), dequeue(), enqueue(1), enqueue(8), dequeue(), enqueue(8), dequeue(). What are its final contents, front to rear (dequeue on empty is a no-op)?
- A. 1, 8, 8
- B. 8, 8, 1
- C. empty
- D. 1, 8
Correct answer: A. 1, 8, 8
A circular queue wraps the rear index modulo its capacity instead of shifting elements on dequeue; tracing front/rear/size through all 9 operations in order leaves [1, 8, 8] 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
- 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…
- An LRU cache of capacity 3 runs this sequence of operations in order: put(8, 80), put(8, 80), put(6, 60), put(7, 70), put(8, 80), put(1…
- Kadane's algorithm runs on the array [2, -8, 4, -2, 4, -5, -2] to find the maximum sum of a contiguous subarray. What sum does it return?
- What is the postfix (Reverse Polish) form of the infix expression "j + e f -(b + a)", built with the standard stack-based conversion (^…
- What is the sum of the minimum element over every contiguous subarray of [8, 1, 5, 4, 4, 2]?
- Binary search for first/last occurrence runs on the sorted array [5, 6, 7, 7, 15, 18, 19, 20] for target 7. What (first index, last index)…