Generate Parentheses

Medium

Generate Parentheses

Problem Statement

Given a set of balanced parentheses, generate all possible combinations of well-formed parentheses that can be obtained by inserting additional pairs of parentheses around existing ones.

Rules and Constraints

  • The generated combinations should only contain valid parentheses (
    '('
    and
    ')'
    ).
  • The resulting strings must have the same number of open and close parentheses.
  • No generated string should have any unmatched open or close parentheses.
  • The order of the parentheses does not matter.

Output Requirements

The solution should return a list of all valid combinations of well-formed parentheses that meet the above constraints.

Notes

  • The input may be an empty string or a string containing balanced parentheses.
  • The time complexity of the solution should be optimized to handle large inputs efficiently.

By following these requirements, you can generate all possible combinations of well-formed parentheses from the input set.

Example

Input: {"n":3} Output: ["((()))","(()())","(())()","()(())","()()()"]

CompaniesGoogle
JavaScript

Login to write code

Solve problems, verify your skills, and earn XP.