Generate parentheses

Write codeMedium20 min

Your task

Generate all well-formed strings of n pairs of parentheses. Return them sorted lexicographically. For n = 0 return a list containing the single empty string. 0 <= n <= 8.

Examples

generate_parentheses(n: int) -> list[str]
Example 1
Inputgenerate_parentheses(3)
Output["((()))", "(()())", "(())()", "()(())", "()()()"]