Pergunta de entrevista da empresa Amazon

Find the maximum value in a stack, with constant complexity

Respostas da entrevista

Sigiloso

12 de jun. de 2012

It's easy to keep track of the highest value when you do push. But it gets tricky when you do pop. You may need two stacks to keep track of it.

1

Sigiloso

9 de jul. de 2012

@Jun: Where is the constant complexity?? You gonna push and pop every element or do you have any specific algo :P

Sigiloso

1 de jun. de 2012

keep track of the highest value when you do a pop and push into the stack. simple.