## Min Stack Leetcode Solution

Problem Statement Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) — Push element x onto stack. pop() — Removes the element on top of the stack. top() — Get the top element. getMin() — Retrieve the minimum element in the stack. …

## Build an Array With Stack Operations Leetcode Solution

The Build an Array With Stack Operations Leetcode Solution problem provides us with an integer sequence and an integer n. The problem states that we are given a sequence of integers from 1 to n. Then we use a stack to produce an integer sequence that is given to us …

## Crawler Log Folder Leetcode Solution

Problem Statement In this problem, we are keep tracking of our position in a folder system. We are initially at the root folder or the main folder of this system. We have basically 3 kind of commands here. The commands are in the form of string in which each string …

## Next Greater Element I Leetcode Solution

Problem Statement In this problem, we are given two lists in which first list is subset of second list. For each element of first list, we have to find out next greater element in the second list. Example nums1 = [4,1,2], nums2 = [1,3,4,2] [-1,3,-1] Explanation: for first element of list1 i.e. for 4 there …

## 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 …

## Make The String Great Leetcode Solution

Problem Statement In “Make The String Great” problem a string is given consists of lower and upper case letters. We have to make this string good by removing adjacent characters in the string which is making the string bad. A good string is a string which doesn’t have two adjacent …

## 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 …

## 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 …

## 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 …

## 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(): …