Coding Challenge

Min Stack

Medium
stackdesign

Design a stack that can return the minimum in constant time.

Implement a stack supporting push, pop, top, and retrieving the minimum element in constant time.

Examples

Input: push(-2), push(0), push(-3), getMin()

Output: -3

Constraints

  • Operations should be O(1)

Preparing your coding workspace...