Expression Evaluation

In expression evaluation problem, we have given a string s of length n representing an expression that may consist of integers, balanced parentheses, and binary operations ( +, -, *, / ). Evaluate the expression. An expression can be in any one of prefix, infix, or postfix notation. Example See …

Read moreExpression Evaluation

How to Create Mergable Stack?

We have to design and create a stack that performs the operations in constant time. Here we have one problem which is how to create mergable stack? Here we perform the below operation for merge two stacks. push(element): Insert the element in the stack. pop(): Remove the top element in …

Read moreHow to Create Mergable Stack?

The Stock Span Problem

This problem “The Stock Span Problem” comes under the financial aspect. In this problem, we find the stock span for the stock price of each day. The maximum number of consecutive days just before any particular day for which the price of the stock of the days before it is …

Read moreThe Stock Span Problem

Reverse a String using Stack

We have given a string s of length n which contains lower case letters, upper case letters, integers, and some special symbol. Reverse the given string using stack. Let’s see some examples for better understanding. Example Input¬† s = “TutorialCup” Output¬† puClairotuT Input s = “Stack” Output kcatS Using Stack …

Read moreReverse a String using Stack

Balanced Expression with Replacement

In Balanced Expression with Replacement problem we have given a string s containing parenthesis i.e. ‘(‘, ‘)’, ‘[‘, ‘]’, ‘{‘, ‘}’. The string also contains x at some places as a replacement of parenthesis. Check if the string can be converted into an expression with valid parenthesis after replacing all …

Read moreBalanced Expression with Replacement

Decode String

Suppose, you are given an encoded string. A string is encoded in some kind of pattern, your task is to decode the string. Let us say, < no of times string occurs > [string ] Example Input 3[b]2[bc] Output bbbcaca Explanation Here “b” occurs 3times and “ca” occur 2 times. …

Read moreDecode String