Check for balanced parentheses in an expression.
You're given string ‘STR’ consisting solely of “{“, “}”, “(“, “)”, “[“ and “]” . Determine whether the parentheses are balanced.
Input Format:
The first line contains an Integer 'T' which denotes the number of test cases or queries to be run. Then the test cases follow.
The first and the only line of input of each test case contains a string, as described in the task.
Output format :
For each test case, the first and the only line of output prints whether the string or expression is balanced or not.
The output of every test case is printed in a separate line.
Note:
You are not required to print anything explicitly. It has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 10
1 <= N <= 10^5
Where N is the length of the input string or expression.
Time Limit: 1 sec
CodingNinjas
author
2y
A stack can be used to solve this question.
We traverse the given string s and if we:
1. see open bracket we put it to stack
2. see closed bracket, then it must be equal to bracket in the top of our sta...read more
CodingNinjas
author
2y
Valid Parenthesis
Make use of the stack. Traverse the string and push the current character in the stack if it is an opening brace else pop from the stack If it is the corresponding starting brace for ...read more
Help your peers!
Add answer anonymously...
Top Snapdeal Software Engineer interview questions & answers
Popular interview questions of Software Engineer
Top HR questions asked in Snapdeal Software Engineer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app