Frage im Vorstellungsgespräch bei SAP

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

Antwort im Vorstellungsgespräch

Anonym

27. März 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