solulubeta
Sign in
Recursion & Memo / Choices and backtracking
02.07 · Problem

Generate Parentheses

Medium Choices with counters LC 22 Pro

Return every valid string of n pairs of brackets: every ( is closed by a later ). Any order is fine.

Examples

Example 1

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

Example 2

Input:  n = 1
Output: ["()"]
solulu Pro

Continue this problem with Pro

Inside: step-by-step hints · 7 hidden tests · reference solutions · code editor.

Lifetime ₹1,999 ₹999 · Launch offer
Mark this problem as solved when you are finished.

Item 18 of 44 · updated 2026-10-13