Algorithm · C3.ai · Medium
You are given an integer n representing how many pairs of parentheses are available. Return all distinct strings that use exactly those n pairs and are balanced, meaning every opening parenthesis is matched by a closing one that comes after it, and no prefix ever contains more closing than opening parentheses. Follow-ups What is the time complexity of your solution? If your solution is recursive, how would you change the order in which it generates the results? Examples…