Back to DSA

Generate Parentheses

medium
Acceptance: 52%
BacktrackingStrings

Given an integer n, produce every arrangement of n pairs of parentheses that is syntactically balanced.

Examples

Example 1:
Input:n = 2
Output:["(())","()()"]
Example 2:
Input:n = 4
Output:["(((())))","((())())","((()))()","(()(()))","(()()())","(()())()","(())(())","(())()()","()((()))","()(()())","()(())()","()()(())","()()()()"]

Hints

00:00
1234567