algorythms
Backtracking
LC #22Medium

Generate Parentheses

Backtracking
GoogleAmazonMetaBloombergMicrosoft

Problem

Given n pairs of parentheses, generate all combinations of well-formed parentheses.

stringbacktrackingdynamic-programming

Constraints

  • 1 ≤ n ≤ 8

Example

Inputn = 3
Output["((()))","(()())","(())()","()(())","()()()"]
Why

All 5 combinations of 3 pairs of valid parentheses

Hints — reveal one at a time