Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

operations =
arguments =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Keep a second stack that stores the minimum value at each depth.

Approach

On push, also push min(val, currentMin) onto minStack. On pop, pop both stacks.

Why it works

minStack mirrors the main stack, so its top always equals the minimum of all elements currently in the stack.

Code
Loading...
Complexity
Time: O(1)
Space: O(n)
Solution
Updated: 2026-02-23

Idea

Keep a second stack that stores the minimum value at each depth.

Approach

On push, also push min(val, currentMin) onto minStack. On pop, pop both stacks.

Why it works

minStack mirrors the main stack, so its top always equals the minimum of all elements currently in the stack.

Code
Loading...
Complexity
Time: O(1)
Space: O(n)