Pregunta de entrevista de SAP

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

Respuesta de la entrevista

Anónimo

27 de mar de 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