Link: https://leetcode.com/problems/generate-parentheses/
Solution:
Topics: DFS, back tracking
Intuition
The idea here is to build out all possible parentheses using two very simple rules.
- If we have not used up
n
open parentheses, add an open parentheses. - If there are more open parentheses than closed, add a closed parentheses.
Each of these conditions is a branch in our tree.
Implementation