Generate Parentheses Problem
Generate Parentheses Problem — ExecCode Medium DSA Practice
Solve the Generate Parentheses problem on ExecCode. Free online medium DSA practice in Backtracking. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Following the diagram logic: - openP: Remaining open brackets to use. - closeP: Remaining close brackets to use. - Goal: Reach (0, 0, string).
Examples
Input n = 1; Output ["()"]. Input n = 2; Output ["(())", "()()"]. Input n = 3; Output ["((()))", "(()())", "(())()", "()(())", "()()()"]
Constraints
1 <= n <= 8
Practice Generate Parentheses free on ExecCode. Browse DSA problems, topic map, and placement guides.