Skip to content
Preptima

Stacks & Queues interview questions

Monotonic stacks, deques, and the parsing and next-greater-element families.

4 questions in Data Structures & Algorithms.

medium2

mediumCodingConcept

Implement a FIFO queue using only two stacks, then tell me what a dequeue costs.

Push arrivals onto an inbound stack and serve departures from an outbound one, transferring everything across only when the outbound stack is empty. Transferring on every dequeue instead reverses the order and breaks FIFO, and the empty-only rule is also what makes the amortised cost constant.

4 minentry, mid, senior

hard2