Balanced Parentheses Combinations
Given an integer N
representing the number of pairs of parentheses, find all the possible combinations of balanced parentheses using the given number of pairs.
Explanation:
Conditions for valid parentheses:
- All open brackets must be closed by the closing brackets.
- Open brackets must be closed in the correct order.
Input:
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:
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.
Example:
For N = 2
, the valid combinations are:
Input:
T = 1
N = 2
Output:
()() (())
Constraints:
1 <= T <= 5
1 <= N <= 10
- Time Limit: 1 sec.
Note:
- You don't need to print anything, it has already been taken care of. Just implement the given function.
- You can return strings in any order.
Be the first one to answer
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