# Category Archives: Stack (adsbygoogle = window.adsbygoogle || []).push({});

## Minimum integer that can be obtained by swapping adjacent digits of different parity

Given an integer N, the task is to find the minimum integer that can be obtained from the given integer such that the adjacent digits… Read More »

## Find the number of unique pairs satisfying given conditions

Given an array arr[] of distinct positive elements, the task is to find the number of unique pairs (a, b) such that a is the… Read More »

## Parsing String of symbols to Expression

Given an expression as a string str consisting of numbers and basic arithmetic operators(+, -, *, /), the task is to solve the expression. Note… Read More »

## Largest row-wise and column-wise sorted sub-matrix

Given an N * M matrix mat[][], the task is to find the area-wise largest rectangular sub-matrix such that each column and each row of… Read More »

## Maximum XOR value of maximum and second maximum element among all possible subarrays

Given an array arr[] of N distinct positive integers, let’s denote max(i, j) and secondMax(i, j) as the maximum and the second maximum element of… Read More »

## Reverse substrings between each pair of parenthesis

Given a string str that consists of lower case English letters and brackets. The task is to reverse the substrings in each pair of matching… Read More »

## Iterative Postorder Traversal of N-ary Tree

Given an N-ary tree, the task is to find the post-order traversal of the given tree iteratively. Examples: Input: 1 / | \ 3 2… Read More »

## Reduce the string to minimum length with the given operation

Given a string str consisting of lowercase and uppercase characters, the task is to find the minimum possible length the string can be reduced to… Read More »

## Sort the given stack elements based on their modulo with K

Given a stack of integers and an integer K, the task is to sort the elements of the given stack using another stack in the… Read More »

## Check if the bracket sequence can be balanced with at most one change in the position of a bracket | Set 2

Given a bracket sequence as a string str, the task is to find whether the given string can be balanced by moving at most one… Read More »

## Check if any K ranges overlap at any point

Given N ranges [L, R] and an integer K, the task is to check if there are any K ranges which overlap at any point.… Read More »

## Stack in Python

A stack is a linear data structure that stores items in a Last-In/First-Out (LIFO) or First-In/Last-Out (FILO) manner. In stack, a new element is added… Read More »

## Find the winner of the Game to Win by erasing any two consecutive similar alphabets

Given a string consisting of lower case alphabets. Rules of the Game: A player can choose a pair of similar consecutive characters and erase them.… Read More »

## Convert ternary expression to Binary Tree using Stack

Given a string str that contains a ternary expression which may be nested. The task is to convert the given ternary expression to a binary… Read More »

## Find all unique pairs of maximum and second maximum elements over all sub-arrays in O(NlogN)

Let represent the ordered pair of the second maximum and the maximum element of an array respectively. We need to find all such unique pairs… Read More »