SAP interview question

Design a stack based data structure in which i can access the minimum element with least time complexity

Interview Answer

Anonymous

27 Mar 2020

Brute force Solution - maintain a variable called minElement. After every push and pop, scan the entire stack and update this variable. Use 2 stacks - in 2nd stack keeping pushing if current element < stack top