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!
Select
Add answer anonymously...

Salesforce Software Developer interview questions & answers

A Software Developer was asked Q. Pair with Given Sum in a Balanced BST Problem Statement You are given the ‘root’...read more
A Software Developer was asked Q. What is the difference between Early Binding and Late Binding in C++?
A Software Developer was asked Q. What is meant by multitasking and multithreading in operating systems?

Popular interview questions of Software Developer

A Software Developer was asked Q1. Pair with Given Sum in a Balanced BST Problem Statement You are given the ‘root’...read more
A Software Developer was asked Q2. What is the difference between Early Binding and Late Binding in C++?
A Software Developer was asked Q3. What is meant by multitasking and multithreading in operating systems?
Salesforce Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits