Category Archives: Queue

Find maximum level sum in Binary Tree

Given a Binary Tree having positive and negative nodes, the task is to find maximum sum level in it. Examples: Input : 4 / \ 2 -5 / \ /\ -1 3 -2 6 Output: 6 Explanation : Sum of all nodes of 0’th level is 4 Sum of all nodes of 1’th level is… Read More »

Implement a stack using single queue

We are given queue data structure, the task is to implement stack using only given queue data structure. We have discussed a solution that uses two queues. In this article, a new solution is discussed that uses only one queue. This solution assumes that we can find size of queue at any point. The idea… Read More »

Implement Stack using Queues

The problem is opposite of this post. We are given a Queue data structure that supports standard operations like enqueue() and dequeue(). We need to implement a Stack data structure using only instances of Queue and queue operations allowed on the instances.