Challenge: Min Stack

Learn how to find the minimum element in a stack.

Problem

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

Input

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

Output

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.