Tell me how you would generate all valid parentheses combinations and explain your backtracking logic.
Implement a function that returns every balanced string containing n pairs of parentheses. Use backtracking to build the strings and avoid exploring invalid partial states.
Function signature: def generate_parentheses(n):
Input: an integer n
Output: a list of strings containing all valid combinations
def generate_parentheses(n):