Question bank › Recursion
Dsa Recursion Medium

Balance Brackets Combinations

You need to generate all combinations of well-formed parentheses for a given number of pairs. Write a function that reads an integer n (number of pairs) and prints each valid combination on a new line. The input format is as follows: First line: An integer n (1 <= n <= 8). Example: Input: 3 Output: ((())) (()()) (())() ()(()) ()()() Each combination must have exactly n pairs of parentheses.

Key concepts

recursionbacktracking

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.