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.

AnswerBot
4mo
Generate all possible combinations of balanced parentheses for a given number of pairs.
Use recursion to generate all possible combinations of balanced parentheses.
Keep track of the number of open and ...read more
Help your peers!
Add answer anonymously...
Info Edge Software Engineer interview questions & answers
A Software Engineer was asked 2mo agoQ. What is Dijkstra's algorithm and how is it applied to graph theory?
A Software Engineer was asked 4mo agoQ. Are you proficient in Excel?
A Software Engineer was asked 10mo agoQ. How do you cope with stress?
Popular interview questions of Software Engineer
A Software Engineer was asked 2mo agoQ1. What is Dijkstra's algorithm and how is it applied to graph theory?
A Software Engineer was asked 4mo agoQ2. Are you proficient in Excel?
A Software Engineer was asked 10mo agoQ3. How do you cope with stress?
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

