Medium · Backtracking

Generate Parentheses

Given an integer n, return every string of n '(' and n ')' characters that is a well-formed (balanced) parentheses sequence, in any order.

Examples

Example 1

n = 3

Output: 5 strings

Example 2

n = 2

Output: 2 strings

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Backtracking problems