Skip to the editor
JSGroundwork
JSGroundwork handwritten · web dev
←Back to Stacks & queues

Ready to read

JSJavaScript⑂Git◎Interview prepΣDSA in JSSDSystem Design
More topics15›
</>HTML{ }CSS⚛ReactNNext.jsNeNest.jsTSTypeScriptNoNode.js🐳DockerDBSQL & Databases✓Testing🔒Web Security☁Cloud & DevOps◈GraphQL◆Redis☸Kubernetes
☰‹›
Description
All topics›JavaScript›Stacks & queues

Min Stack

beginnerlayer B8 · Stacks & queues4 tests

Design a stack that supports the usual operations plus a getMin() that reports the smallest value currently on the stack — every operation must run in O(1).

  • push(val) — put val on top
  • pop() — remove the top value and return it
  • top() — return the top value without removing it
  • getMin() — return the smallest value on the stack
  • Scanning the whole stack inside getMin is not allowed
  • Duplicated minimums must keep working: after pushing 3 twice and popping once, the minimum is still 3

Stuck?

All exercisesPlayground
1234567891011121314
loading the editor…

Nothing yet — hit Run and whatever you log shows up here.

Submit to see how you did.

⌘/Ctrl + Enter run⌘/Ctrl + S save⌘/Ctrl + / comment⌘/Ctrl + F find/replace⌘/Ctrl + D select next matchAlt + click multi-cursorTab indent · ⇧Tab outdentEsc leave fullscreen