Category Archives: Stack

The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to… Read More
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… Read More
Given preorder traversal of a binary search tree, construct the BST. For example, if the given traversal is {10, 5, 1, 7, 40, 50}, then… Read More
In a party of N people, only one person is known to everyone. Such a person may be present in the party, if yes, (s)he… Read More
Create a data structure twoStacks that represents two stacks. Implementation of twoStacks should use only one array, i.e., both stacks should use the same array… Read More
Question: Design a Data Structure SpecialStack that supports all the stack operations like push(), pop(), isEmpty(), isFull() and an additional operation getMin() which should return… Read More
Spaghetti stack A spaghetti stack is an N-ary tree data structure in which child nodes have pointers to the parent nodes (but not vice-versa) Spaghetti… Read More
Given an array, print the Next Greater Element (NGE) for every element. The Next greater Element for an element x is the first greater element… Read More
Write a program to reverse a stack using recursion. You are not allowed to use loop constructs like while, for..etc, and you can only use… Read More
  Given an expression string exp, write a program to examine whether the pairs and the orders of “{“, “}”, “(“, “)”, “[“, “]” are… Read More
Using Stack is the obvious way to traverse tree without recursion. Below is an algorithm for traversing binary tree using stack. See this for step… Read More
The problem is opposite of this post. We are given a stack data structure with push and pop operations, the task is to implement a… Read More
Write a function to print spiral order traversal of a tree. For below tree, function should print 1, 2, 3, 4, 5, 6, 7.    … Read More