employer cover photo
employer logo

Pregunta de entrevista de Opower

Implement a queue using only stacks.

Respuestas de entrevistas

Anónimo

28 de may de 2011

actually this is doable with 2 stacks nvm: use 2 Stacks, stackA and stackB. when you enqueue, push the item onto stackA. When you dequeue, if stackB is empty pop everything from stackA and push onto stack B. Pop from stackB

3

Anónimo

28 de may de 2011

use 2 Stacks, stackA and stackB. when you enqueue, push the item onto stackA. When you dequeue, pop everything from stackA and push onto stack B. Pop from stackB.

1

Anónimo

13 de jun de 2018

#3 corrected use 2 stacks. it depedents server IP address availabe.

Anónimo

28 de may de 2011

the above answer is incorrect. I can't figure out how to edit, so here is the corrected version: use 3 Stacks, stackA, stackB, stackC. when you enqueue, push the item onto stackA. When you dequeue, pop everything from stackB and push onto stackC, pop everything from stackA and push onto stack B, pop everything from stackC and push onto stackB. Pop from stackB.