Backtracking
LC #22Medium
Generate Parentheses
Backtracking
GoogleAmazonMetaBloombergMicrosoftProblem
Given n pairs of parentheses, generate all combinations of well-formed parentheses.
stringbacktrackingdynamic-programming
Constraints
- ›1 ≤ n ≤ 8
Example
Input
n = 3Output
["((()))","(()())","(())()","()(())","()()()"]Why
All 5 combinations of 3 pairs of valid parentheses