Java Stack Example

What is a Java Stack class? A Java stack class implementation is based on the stack data structure. It follows the concept of the Last-In-First-Out(LIFO) concept which means the element that we insert last will be removed first. In other words, we can delete elements only from the top of …

Read moreJava Stack Example

Check if a given array can represent Preorder Traversal of Binary Search Tree

The problem “Check if a given array can represent Preorder Traversal of Binary Search Tree” states that you are given a preorder traversal sequence. Now consider this sequence and find out if this sequence can represent a binary search tree or not? The expected time complexity for the solution is …

Read moreCheck if a given array can represent Preorder Traversal of Binary Search Tree

Form minimum number from given sequence

The problem “Form minimum number from given sequence” states that you are given some pattern of I’s and D’s only. The meaning of I stands for increasing and for decreasing we are provided with D. The problem statement asks to print the minimum number which satisfies the given pattern. We have …

Read moreForm minimum number from given sequence

Range Queries for Longest Correct Bracket Subsequence

You are given a sequence of some brackets subsequence, in other words, you are given brackets like ‘(’ and ‘)’ and you are given a query range as a starting point and ending point. The problem “Range Queries for Longest Correct Bracket Subsequence” asks to find out the maximum length …

Read moreRange Queries for Longest Correct Bracket Subsequence

Max stack

Problem Statement The problem “Max stack” states to design a special stack which can perform these operations : push(x): push one element into the stack. top(): returns the element that is at the top of the stack. pop(): remove the element from the stack which is at the top. peekmax(): …

Read moreMax stack

Find Index of Closing Bracket for a Given Opening Bracket in an Expression

Problem Statement Given a string s of length/size n and an integer value representing the index of an opening square bracket. Find index of closing bracket for a given opening bracket in an expression. Example s = “[ABC[23]][89]” index = 0 8 s = “[C-[D]]” index = 3 5 s …

Read moreFind Index of Closing Bracket for a Given Opening Bracket in an Expression

Design a stack that supports getMin() in O(1) time and O(1) extra space

Design a stack that supports getMin() in O(1) time and O(1) extra space. Thus the special stack data structure must support all the operations of the stack like – void push() int pop() bool isFull() bool isEmpty() in constant time. Add an additional operation getMin() to return the minimum value …

Read moreDesign a stack that supports getMin() in O(1) time and O(1) extra space