Data Structures & AlgorithmsHardProduct Company SDE · stack round
Problem: Which structure supports push, pop and getting the minimum, all in O(1) amortised time?
- A. A plain queue
- B. A hash map alone
- C. A sorted array with binary search only
- D. A stack of (value, current minimum) pairs or a monotonic stack
Correct answer: D. A stack of (value, current minimum) pairs or a monotonic stack
Storing the running minimum with each stack entry keeps every operation constant time.
More Coding Interview Problems questions
- Problem: Which property makes counting sort stable and therefore usable inside radix sort?
- Problem: Which structure gives a queue with O(1) amortised enqueue, dequeue and minimum queries?
- 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…