
Asked in Info Edge
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...
Top Software Engineer Interview Questions Asked at Info Edge
Q. What is Dijkstra's algorithm and how is it applied to graph theory?
Q. What are the pillars of OOPS?
Q. Given a set of coin denominations and a target value, find the minimum number of...read more
Interview Questions Asked to Software Engineer at Other Companies
Top Skill-Based Questions for Info Edge Software Engineer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
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

