Sign In
You are coding as a Guest. Sign in with your RoleNest account to permanently track your streak, earn XP, and climb the Campus Leaderboard!
Sign In with RoleNest
🔥Generate Parentheses: Backtracking TreeMedium
MediumStack•Acceptance: 74.8%

Generate Parentheses: Backtracking Tree

Real-World Engineering Context
AST parser generation, mathematical formula validation, and compiler grammar tree construction.
Given `n` pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

Sample Test Cases

Input: [3]
Expected: ["((()))","(()())","(())()","()(())","()()()"]
Input: [1]
Expected: ["()"]

Constraints

  • 1 <= n <= 8