# Category Archives: Stack

## Remove brackets from an algebraic string containing + and – operatorsSeptember 2, 2017

Simplify a given algebraic string of characters, ‘+’, ‘-‘ operators and parentheses. Output the simplified string without parentheses. Examples: Input : “a-(b+c)” Output : “a-b-c”… Read More »

## Interleave the first half of the queue with second halfAugust 30, 2017

Given a queue of integers of even length, rearrange the elements by interleaving the first half of the queue with the second half of the… Read More »

## Check if stack elements are pairwise consecutive

Given a stack of integers, write a function pairWiseConsecutive() that checks whether numbers in the stack are pairwise consecutive or not. The pairs can be… Read More »

## Reversing a QueueAugust 20, 2017

Give an algorithm for reversing a queue Q. Only following standard operations are allowed on queue. enqueue(x) : Add an item x to rear of… Read More »

## Reversing the first K elements of a QueueAugust 16, 2017

Given an integer k and a queue of integers, we need to reverse the order of the first k elements of the queue, leaving the… Read More »

## Reverse a number using stackAugust 1, 2017

Given a number , write a program to reverse this number using stack. Examples: Input : 365 Output : 563 Input : 6899 Output :… Read More »

## Check mirror in n-ary treeJuly 27, 2017

Given two n-ary trees, the task is to check if they are mirror of each other or not. Print “Yes” if they are mirror of… Read More »

## Tracking current Maximum Element in a StackJuly 21, 2017

Given a Stack, keep track of the maximum value in it. The maximum value may be the top element of the stack, but once a… Read More »

## Stack Permutations (Check if an array is stack permutation of other)

A stack permutation is a permutation of objects in the given input queue which is done by transferring elements from input queue to the output… Read More »

## Iterative method to find ancestors of a given binary treeJuly 17, 2017

Given a binary tree, print all the ancestors of a particular key existing in the tree without using recursion. Here we will be discussing the… Read More »

## Create a customized data structure which evaluates functions in O(1)July 12, 2017

Create a customized data structure such that it has functions :- GetLastElement(); RemoveLastElement(); AddElement() GetMin() All the functions should be of O(1) Question Source :… Read More »

## Sort a stack using a temporary stackJuly 1, 2017

Given a stack of integers, sort it in ascending order using another temporary stack. Examples: Input : [34, 3, 31, 98, 92, 23] Output :… Read More »

## Pattern Occurrences : Stack Implementation JavaJune 24, 2017

Suppose we have two Strings :- Pattern and Text pattern: consisting of unique characters text: consisting of any length We need to find the number… Read More »

## Bubble sort using two StacksJune 22, 2017

Prerequisite : Bubble Sort Write a function that sort an array of integers using stacks and also uses bubble sort paradigm. Recommended: Please try your… Read More »

## Decode a string recursively encoded as count followed by substring

An encoded string (s) is given, the task is to decode it. The pattern in which the strings are encoded is as follows. <count>[sub_str] ==>… Read More »