Balanced Parentheses Check
Given a string STR
consisting 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. Each of the following T lines contains a string representing a test case.
Output:
For each test case, output 'YES' if the expression is balanced and 'NO' otherwise. Each result should be printed on a new line.
Example:
Input:
3
{}[()]
{[}]
({[()]})
Output:
YES
NO
YES
Constraints:
1 <= T <= 10
1 <= N <= 10^5
- Where N is the length of the input string or expression.
Note: You don't need to print anything yourself; just implement the function to solve the problem.

AnswerBot
4mo
Implement a function to check if parentheses in a string are balanced.
Use a stack to keep track of opening parentheses and pop when a closing parenthesis is encountered.
If the stack is empty when a cl...read more
Help your peers!
Add answer anonymously...
Snapdeal Software Engineer interview questions & answers
A Software Engineer was asked Q. Given a binary tree, return the vertical sum of the tree.
A Software Engineer was asked Q. How many rectangles/squares are there on a chessboard?
A Software Engineer was asked Q. How would you dynamically calculate the top 10 most frequent words on Facebook w...read more
Popular interview questions of Software Engineer
A Software Engineer was asked Q1. Given an array, find a pair of elements.
A Software Engineer was asked Q2. Given a binary tree, return the vertical sum of the tree.
A Software Engineer was asked Q3. How many rectangles/squares are there on a chessboard?
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

