Generate all Balanced Parentheses

preview_player
Показать описание


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

For example, given n = 3, a solution set is:

"((()))", "(()())", "(())()", "()(())", "()()()" .
------------------------------------------------------------------------------------------
Here are some of the gears that I use almost everyday:

PS: While having good gears help you perform efficiently, don’t get under the impression that they will make you successful without any hard work.
Рекомендации по теме
Комментарии
Автор

The way you explained the choice + decision, and the IP/OP method is so cool that for the second half of the recursion playlist all I had to do was listen to the question and directly solve the problem without looking at any solution. Thanks so much man! Cheers and All the very best in all your endeavours.

nitinneo
Автор

We hope you can increase your frequency dude! Your teaching standard is way to high compared to any other YouTuber in programming domain. You make them so simple and subtle. Great work, Aditya. Keep uploading more videos. People are now ready to even pay exclusively for your videos.

ashishkempwad
Автор

Can't believe I solved this once impossible looking problem on my own now! I don't fear recursion anymore. Thank you so much bro!!

akshatw
Автор

I've watched your DP playlist and I don't really think anyone else could have explained it better than you. You don't just tell the solution/code but also help us develop the intuition for problems(which is what DSA is all about). It's been really really helpful. Now I'm struggling hard with backtracking, even if I view the editorials, I'm not able to develop the thought process and wonder how would I ever be able to think in that particular way and solve the problem myself. So it's a request pls pls make a playlist on backtracking🙏🙏(if not all problems at least a few basic ones) so that we could learn how to approach the problems.

sakshiramsinghani
Автор

This is happiest notification I got, Aditya verma uploaded a new video

AnkitKumar-ftyu
Автор

Dude you're amazing. Paused the vid at 10 minutes and solved the question. Never thought recursion could be taught in such a easy way!

ritavdas
Автор

Woah! I can't believe I was able to solve this problem without watching the video. It's because I have been following this playlist. Thanks for teaching such an easy approach!!

tanyaagarwal
Автор

I still do not believe how i am able to write the code myself after watching the explanation! You are a gem bro

HemanthaKumarYadav
Автор

Tried to learn from other youtube channels but addicted to ur teaching style no one can beat that

amruthachowdary
Автор

It did it a litttle bit differently. And It WORKS!! Used your technique again!!!💕
char L = '(', R = ')';
void parenthesis(string output, int left, int right)
{
if (left == 0 && right == 0)
{
cout << output << endl;
return;
}
if (left == right)
{
output += L;
left--;
}
if (left == 0)
{
parenthesis(output + R, left, right - 1);
return;
}

parenthesis(output + L, left - 1, right);
parenthesis(output + R, left, right - 1);
}

AshutoshDahal-lful
Автор

You made it so easy. I code it myself after watching first 10 minutes

LokeshSharma-hmjz
Автор

I was thinking about these conditions:
1)Base condition (op1, op2)(--open, --close)
2)open==close (op1)(--open)
3)open<close (op1, op2)(--open, --close)
4)open==0 (op2)(--close)

op1=op1+'{'
op2=op2+'}'

vishalwaghmare
Автор

I never thought I could solve recursion problems that need 3-4 recursive calls so quickly. I always got stuck in recursive stack calls but this IP/OP method made things easy. Thanks, for all your hard work and these playlists.

adityaagarwal
Автор

Bhaiya you made my day by teaching this problem in the easiest way I struggled to understand it but now it's easy

parasjain
Автор

this solution can be improved by adjusting the base condition, if we just run a for loop when open == 0, and push all the close parenthesis, it'll take fewer recursive calls,
this solution took 17 recursive calls while mine did it in 8 for n = 3


here is the base condition

if (open == 0) {
for (int i = 0; i < close; i++) {
op.push_back(')');
}
vec.push_back(op);
return;
}

baibhav
Автор

bro honestly your teaching technique is too good, i am able to code myself after seeing only explanation .

harshvardhanyadav
Автор

finally after so long bro, thanks a lot <3

noobninja
Автор

This is the best explanation for this problem I found on YouTube

ninadxperia
Автор

I declare your videos are best for programming, couldn't be more helpful.

vikrantsagar
Автор

Oh my goodness!!!.. Initially when I saw this question literally I was scared and paused this video and I thought 'Just give a try dude'. guess what? I solved it on my own without even referring the comment/discussion section. this is crazy, Im really really happy right now. Thank you sir Aditya ji. I wish every university should officially play these video lectures right in the class instead of those boring live classes. :)

shirish