Balanced parentheses
Given an integer ‘N’ representing the number of pairs of parentheses, Find all the possible combinations of balanced parentheses with the given number of pairs of parentheses.
Note :
Conditions for valid parentheses:
1. All open brackets must be closed by the closing brackets.
2. Open brackets must be closed in the correct order.
For Example :
()()()() is a valid parentheses.
)()()( is not a valid parentheses.
Input format :
The first line of input contains an integer ‘T’, which denotes the number of test cases. Then each test case follows.
Each line of the test case contains an integer ‘N’ denoting the pair of parentheses.
Output format :
For each test case print, all the combinations of balanced parentheses separated by a single space.
The output of each test case will be printed on a separate line.
Note:
1. You don't need to print anything, it has already been taken care of. Just implement the given function.
2. You can return strings in any order.
Constraints:
1 <= T <= 5
1 <= N <= 10
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
Recursion
The idea is to generate all possible combinations and check whether the combination is the combination of balanced parentheses or not. We have two choices whether to consider ‘(‘ or ‘)’.
When ...read more
Help your peers!
Add answer anonymously...
Top Info Edge Software Engineer interview questions & answers
Popular interview questions of Software Engineer
Top HR questions asked in Info Edge 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