โœ๏ธ

Min Stack

Medium๐Ÿท๏ธ Stacks & queues๐Ÿ“‚ Stacks & Queues
๐Ÿงฉ The problem

Design a stack that supports push(x), pop(), top() and getMin() โ€” all in O(1). The tests run a list of commands and print the results of top and getMin.

Examples

  • push 5, push 3, getMin โ†’ 3, pop, getMin โ†’ 5

๐ŸŽฏ Aim for: O(1) per operation

โœ๏ธ Write your solution

Pick a language, press Run to try it, then Run tests to check it against every test case โ€” just like a coding interview.

โ† All practice problems