C/C++ Arena

Step 8 of 8

Challenge: a MinStack<T>

A classic interview question, now generic. Your turn: write template <typename T> class MinStack where every operation is O(1), including finding the minimum:

Hint for the O(1) min: alongside each value, remember what the minimum was at that point. Or keep a second stack of minimums.

Previous: Template specialization