Data Structures & AlgorithmsHardProduct Company SDE · data structures
Problem: Which structure gives a queue with O(1) amortised enqueue, dequeue and minimum queries?
- A. A binary search tree with rebalancing only
- B. Two stacks with running minima, or a monotonic deque
- C. A hash table
- D. A linked list alone
Correct answer: B. Two stacks with running minima, or a monotonic deque
Two stacks each store running minima, so the queue minimum is the smaller of the two stack tops.
More Coding Interview Problems questions
- Problem: The Chinese remainder theorem gives a unique solution modulo M for a system of congruences under which condition?
- Problem: What guarantee does the maximal-matching heuristic give for vertex cover?
- Problem: Which problem is the standard application of the monotonic deque?
- Problem: What is the expected number of random probes needed in open-addressing hashing with load factor alpha under uniform probing…
- Problem: What is the complexity of checking whether a number n is prime by trial division up to sqrt(n)?
- Problem: Edges of an undirected graph on vertices 0–4 are processed in the given order: e1 = 0-1, e2 = 1-2, e3 = 2-3, e4 = 3-4, e5 = 4-0…