First, solving it with numbers. Each solution string is represented by an array of numbers with number incrementing for "(" and decrementing for ")".
For example, "(())()" is [1, 2, 1, 0, 1, 0]
The recursive helper function "solveWithNumbers" receives the beginning of a solution and returns an array with all complete solutions starting with these numbers.
The function "paren" runs "solveWithNumbers" and then converts the solution to the required format
Typescript!
First, solving it with numbers. Each solution string is represented by an array of numbers with number incrementing for "(" and decrementing for ")".
For example, "(())()" is [1, 2, 1, 0, 1, 0]
The recursive helper function "solveWithNumbers" receives the beginning of a solution and returns an array with all complete solutions starting with these numbers.
The function "paren" runs "solveWithNumbers" and then converts the solution to the required format
[stackblitz.com/edit/typescript-n51vvd]