Valid Parenthesis Problem Statement
Given a string str
composed solely of the characters "{", "}", "(", ")", "[", and "]", determine whether the parentheses are balanced.
Input:
The first line contains an integer 'T' representing the number of test cases. For each test case, there is a single line containing a string as described.
Output:
For each test case, output a single line indicating if the string is balanced or not.
Example:
Input:
T = 2
STR = "{[()]}"
STR = "{[(])}"
Output:
YES
NO
Explanation:
The first string is balanced whereas the second is not.
Constraints:
1 <= T <= 10
1 <= N <= 10^5
- Where N is the length of the input string.
- Time Limit: 1 sec
Note:
You are not required to print anything explicitly. Just implement the function.

AnswerBot
4mo
The task is to determine if the given string of parentheses is balanced or not.
Use a stack to keep track of opening parentheses
When encountering a closing parenthesis, check if it matches the top of t...read more
Help your peers!
Add answer anonymously...
Infosys System Engineer interview questions & answers
A System Engineer was asked 6d agoQ. What is the process for reversing a number?
A System Engineer was asked 6d agoQ. What is method overriding?
A System Engineer was asked 1w agoQ. What are the details of Object-Oriented Programming (OOP) concepts?
Popular interview questions of System Engineer
A System Engineer was asked 1w agoQ1. What are the details of Object-Oriented Programming (OOP) concepts?
A System Engineer was asked 2w agoQ2. What are some Java frameworks, and what are the differences among them?
A System Engineer was asked 1mo agoQ3. What are the key concepts of Object-Oriented Programming (OOP)?
Top HR questions asked in Infosys System Engineer
A System Engineer was asked 2mo agoQ1. Explain your project.
A System Engineer was asked 3mo agoQ2. Explain your final semester project.
A System Engineer was asked 3mo agoQ3. What was your involvement in your college project?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

