package main

func generateParenthesis( n int ) []string {
    // write code here
    ans, oneShot := []string{}, []byte{}
    var helper func(int, int)
    helper = func(lBracketNum, rBracketNum int) {
        if len(oneShot) == 2 * n {
            ans = append(ans, string(oneShot))
            return  
        }
        if lBracketNum > 0 {
            oneShot = append(oneShot, '(')
            helper(lBracketNum-1, rBracketNum)
            oneShot = oneShot[:len(oneShot)-1]
        }
        if rBracketNum > 0 && rBracketNum > lBracketNum {
            oneShot = append(oneShot, ')')
            helper(lBracketNum, rBracketNum-1)
            oneShot = oneShot[:len(oneShot)-1]
        }
    } 
    helper(n, n)
    return ans
}