Leetcode 22. Generate Parentheses
Given a number n, generate all distinct well-formed parentheses strings formed from n pairs of opening and closing brackets. Return all valid combinations as a list of strings. Every valid combination is a length-2n sequence where every prefix has at least as many '(' as ')'. This combinatorial generation problem is typically solved with backtracking/DFS by choosing to add '(' or ')' while tracking remaining opens/closes (result count grows as the nth Catalan number; n ≤ 8).
Asked at:
Microsoft
Salesforce
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
0
Late April, 2026
Salesforce
Senior
Mid January, 2026
Junior
Hello Interview Premium
Your account is free and you can post anonymously if you choose.