Domanda di colloquio di SAP

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

Risposta di colloquio

Anonimo

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