Discuss the algorithm?

I am not able to think the algorithm using backtracking so kindly discuss it

hello @namangarg31

  • Keep track of counts of open and close brackets.
  • Initialize these counts as 0.
  • Recursively call the generateParenthesis() function until open bracket count is less than the given n.
  • If open bracket count becomes more than the close bracket count, then put a closing bracket and recursively call for the remaining brackets.
  • If open bracket count is less than n, then put an opening bracket and call _printParenthesis() for the remaining brackets.