0% found this document useful (0 votes)
2 views2 pages

Stack Problems Java Infosys TCS

The document outlines the top 10 stack problems commonly encountered in Java programming for Infosys/TCS. Each problem includes a brief description, input and output examples, and references to earlier code for implementation. The problems range from validating parentheses to decoding strings and evaluating expressions.

Uploaded by

yamini3366
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Stack Problems Java Infosys TCS

The document outlines the top 10 stack problems commonly encountered in Java programming for Infosys/TCS. Each problem includes a brief description, input and output examples, and references to earlier code for implementation. The problems range from validating parentheses to decoding strings and evaluating expressions.

Uploaded by

yamini3366
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Top 10 Stack Problems for Infosys/TCS (Java)

Valid Parentheses
Given a string containing brackets, determine if it is valid.
Input: ()[]{}
Output: true
import [Link].*;
public class Main{
public static boolean isValid(String s){Stack<Character>st=new Stack<>();for(char c:[Link]()){
public static void main(String[]args){[Link](isValid("()[]{}"));}}

Min Stack
Design a stack supporting push, pop, top and getMin.
Input: push operations
Output: minimum element
See earlier code.

Implement Stack Using Queues


Implement stack using queue operations.
Input: push/pop
Output: stack behavior
See earlier code.

Baseball Game
Calculate score using stack rules.
Input: [5,2,C,D,+]
Output: 30
See earlier code.

Backspace String Compare


Compare strings after backspace processing.
Input: ab#c ad#c
Output: true
See earlier code.

Remove Adjacent Duplicates


Remove adjacent duplicates repeatedly.
Input: abbaca
Output: ca
See earlier code.
Next Greater Element
Find next greater element for each array value.
Input: [4,5,2,25]
Output: [5,25,25,-1]
See earlier code.

Daily Temperatures
Find days until warmer temperature.
Input: [73,74,75,71,69,72,76,73]
Output: [1,1,4,2,1,1,0,0]
See earlier code.

Evaluate Reverse Polish Notation


Evaluate postfix expression.
Input: [2,1,+,3,*]
Output: 9
See earlier code.

Decode String
Decode encoded string.
Input: 3[a2[c]]
Output: accaccacc
See earlier code.

You might also like