PREP41 Editorial

Problem Explanation

We have to find all valid pairs of N parenthesis.

Approach

We can use Recursion and Backtracking to solve this problem. We keep a count of leftBrackets left to be used and rightBrackets left to be used which is N at the beginning. If we use up all the left and right brackets, we push the string into the array and return. Otherwise we push either brackets all call the function again with updated count of remaining left and right brackets.