Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

Recursion Graph below tells us that first we will fill all left brackets and while filling right brackets , we will check whether the count of left bracket is greater so that we can add right bracket in the tree.

Hope it will help someone to understand better how can we make problem simple by taking it as a tree.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store