Skip to content

Practice Generate Parentheses

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#22
LeetCode Problem

Generate Parentheses

Problem Statement

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

Source: Generate Parentheses on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 3
Output
["((()))","(()())","(())()","()(())","()()()"]

# Example 2

Input
n = 1
Output
["()"]

Constraints

1 <= n <= 8

Related LeetCode Problems

Practice more problems similar to Generate Parentheses.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.