Skip to content
CampusEduX

Generate Balanced Parentheses

Mediumjavapythonccppjavascript

Given N pairs of parentheses, generate every string of 2N characters in which every opening parenthesis is correctly matched.

Input Format

A single line containing the integer N.

Output Format

Print all valid strings, one per line, in lexicographic order (treating ( as smaller than )).

Related Problems

  • Generate All Subsets
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Generate All Permutations
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Tower of Hanoi
    Medium · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...