At 28:08, in lpsBottomUp function, after initializing array, add following to make all values of diagonal to 1: for (int i = 0; i < str.length(); i++) { arr[i][i] = 1; } - I've corrected in Source code: thecodingsimplified.com/longest-palindromic-subsequence/
@rohitpawar40963 жыл бұрын
int palan(String s,int i,int j,int dp[][]){ if(i>j) return 0; if(i==j){ return dp[i][j]= 1; } if(dp[i][j]!=-1){ return dp[i][j]; } if(s.charAt(i)==s.charAt(j)){ return dp[i][j]= 2+palan(s,i+1,j-1,dp); } int a=palan(s,i+1,j,dp); int b=palan(s,i,j-1,dp); return dp[i][j]=Math.max(a,b); } thats my code for Lps for number problem is that's i want to generate palindrom string using 2d dp array can you do it plz any other can do then comment the code.
@sanjogpanda25973 жыл бұрын
Really helpful for java students. Kudos to your great work!
@CodingSimplified3 жыл бұрын
Thanks for your nice feedback. Keep watching out other videos as well.
@HareeshKumar-g4k Жыл бұрын
Hi, The Topdown approach has failed some of the test cases, below is the one of the test cases tkjprepggxrpnrvystmwcysyycqpevikeffmznimkkasvwsrenzkycxfxtlsgypsfadpooefxzbcoejuvpvaboygpoeylfpbnpljvrvipyamyehwqnqrqpmxujjloovaowuxwhmsncbxcoksfzkvatxdknlyjyhfixjswnkkufnuxxzrzbmnmgqooketlyhnkoaugzqrcddiuteiojwayyzpvscmpsajlfvgubfaaovlzylntrkdcpwsrtesjwhdizcobzcnfwlqijtvdwvxhrcbldvgylwgbusbmborxtlhcsmpxohgmgnkeufdxotogbgxpeyanfetcu Code's output is: 108 It's Correct output is: 107 Thank you very much for the explanation!!
@tirupatirao75214 жыл бұрын
Thank you very much sir, This is very helpful and please never stop your teaching, it will help so many people
@CodingSimplified4 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@tabeebyeamin90023 жыл бұрын
Best explanation of this problem I could find!
@CodingSimplified3 жыл бұрын
Thanks for your nice feedback. Keep Watching
@pinkylover9112 жыл бұрын
Thanks for the great explanation
@CodingSimplified2 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@tirupatirao75214 жыл бұрын
I would have visited this channel before I wasted my interview preparation time by looking ambiguous lectures from other sources, as I am not getting the core of DP, Greedy, recursion etc..
@CodingSimplified4 жыл бұрын
Thanks for nice words. Glad you liked content & channel. Keep Watching.
@barunsarraf88634 жыл бұрын
Thanks a lot. This question was hitting me from the last week. Thanks a lot
@CodingSimplified4 жыл бұрын
Glad it was helpful!
@omerl64154 жыл бұрын
Very well explained. Helped me a lot, thank you!
@CodingSimplified4 жыл бұрын
Thanks. Keep Watching.
@y7klixx2 жыл бұрын
The video was very helpful, thank you :)
@CodingSimplified2 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@commando88222 жыл бұрын
Great explanation!!
@CodingSimplified2 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@divanshmahajan17694 жыл бұрын
reverse the string and find lcs with original string..how does this soln work??
@TheRajmoney4 жыл бұрын
Excellent, i like the explanation and different approaches. However, how do you print the string efficiently? I see alot of videos miss out on this part.
@CodingSimplified4 жыл бұрын
Hi, I didn't get the question. Which String you're mentioning here. Could you please elaborate it, so that I can check it.
@TheRajmoney4 жыл бұрын
@@CodingSimplified how do you print the solution in string rather than returning just the length.
@TheRajmoney4 жыл бұрын
If longest palindromic subsequence is aba, How do we print that string from the table rather than returning just 3.
@surajgrandhi67424 жыл бұрын
www.geeksforgeeks.org/print-longest-palindromic-subsequence/ you can see that here
@dheerajck38814 жыл бұрын
why you add +2 if they are equal on bottum up approach for string abba longest substring is 4 but using this approach we initialize to 1 and coninue so adding 2 to this will.not give 4 Could you reply on this
@y.ashoknaidu57873 жыл бұрын
Well explained sir, ur great sir
@CodingSimplified2 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@AyushKumar-vh7pg4 жыл бұрын
Sir why are we beginning the loop in bottom-up approach from end i didn't get that part
@CodingSimplified4 жыл бұрын
You can even start from top, if you start from top, it'll fill left diagonal side. There's no specific reason. Just that we want to cover basic to complete string, so any one of diagonal you need to fill. Left or right diagonal side.
@adarshgoyal58904 жыл бұрын
Thank uu sir for this solution
@CodingSimplified4 жыл бұрын
Thanks Adarsh for your feedback. Keep Watching.
@arepallipriyanka37373 жыл бұрын
String is not printing how to print palindrome string?