Data Structures & AlgorithmsHard

A min-stack stores a pair (value, current minimum) per entry. Why does popping never require recomputing the minimum?

  1. A. Because the minimum of the stack below an entry is already stored with that entry, so popping restores the previous minimum directly.
  2. B. Because the minimum is always the most recently pushed value.
  3. C. Because pop only ever removes the minimum element.
  4. D. Because the stack is kept sorted at all times.

Correct answer: A. Because the minimum of the stack below an entry is already stored with that entry, so popping restores the previous minimum directly.

Each entry records the minimum of everything at or below it, so the stack below always carries its own correct minimum. Popping simply exposes the entry beneath, with no scan needed.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic