Generate Paranthesis

Recursion Implementation Problems Easy

Given an integer n.Generate all possible combinations of well-formed parentheses of length 2 x N.

Examples:

Input : n = 3

Output : [ "((()))" , "(()())" , "(())()" , "()(())" , "()()()" ]

Input : 2

Output : [ "(())" , "()()" ]

Input : 1

Constraints

  • 1 <= n <= 8

Hints

  • Start with an empty string and keep adding ( or ) recursively. If the string has 2×n characters, add it to the result.
  • Use a backtracking approach where you explore all possibilities and backtrack when the current combination is invalid.

Company Tags

Reddit Texas Instruments DoorDash Lyft Philips Healthcare PayPal Splunk Rakuten Zomato Etsy Walmart American Express Flipkart Stripe KPMG Siemens Healthineers Zoho Intel Uber Epic Systems Unity Technologies Boston Consulting Group Bungie Cerner Freshworks TCS Cognizant Accenture Infosys Capgemini Wipro