Skip to main content
LeetCode 22, Medium. Topics: String, Dynamic Programming, Backtracking. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 11 parametrized pytest cases, and a playground notebook:

Problem

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

Examples

Constraints

  • 1 <= n <= 8

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Grind, NeetCode 150, NeetCode 250, NeetCode All.
Last modified on August 25, 2026