Challenge: Min Stack

Learn how to find the minimum element in a stack.


Write code that returns the minimum value in a stack in O(1)O(1). In other words, implement the MinStack ADT.


An integer array from which a MinStack ADT is to be created.


Returns minimum number in O(1)O(1) time.

Sample input

array = {9, 3, 1, 4, 2, 5}

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.