DP - 9: Longest Palindrome Subsequence

  Рет қаралды 10,830

Coding Simplified

Coding Simplified

Күн бұрын

Пікірлер: 39
@CodingSimplified
@CodingSimplified 4 жыл бұрын
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/
@rohitpawar4096
@rohitpawar4096 3 жыл бұрын
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.
@sanjogpanda2597
@sanjogpanda2597 3 жыл бұрын
Really helpful for java students. Kudos to your great work!
@CodingSimplified
@CodingSimplified 3 жыл бұрын
Thanks for your nice feedback. Keep watching out other videos as well.
@HareeshKumar-g4k
@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!!
@tirupatirao7521
@tirupatirao7521 4 жыл бұрын
Thank you very much sir, This is very helpful and please never stop your teaching, it will help so many people
@CodingSimplified
@CodingSimplified 4 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@tabeebyeamin9002
@tabeebyeamin9002 3 жыл бұрын
Best explanation of this problem I could find!
@CodingSimplified
@CodingSimplified 3 жыл бұрын
Thanks for your nice feedback. Keep Watching
@pinkylover911
@pinkylover911 2 жыл бұрын
Thanks for the great explanation
@CodingSimplified
@CodingSimplified 2 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@tirupatirao7521
@tirupatirao7521 4 жыл бұрын
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..
@CodingSimplified
@CodingSimplified 4 жыл бұрын
Thanks for nice words. Glad you liked content & channel. Keep Watching.
@barunsarraf8863
@barunsarraf8863 4 жыл бұрын
Thanks a lot. This question was hitting me from the last week. Thanks a lot
@CodingSimplified
@CodingSimplified 4 жыл бұрын
Glad it was helpful!
@omerl6415
@omerl6415 4 жыл бұрын
Very well explained. Helped me a lot, thank you!
@CodingSimplified
@CodingSimplified 4 жыл бұрын
Thanks. Keep Watching.
@y7klixx
@y7klixx 2 жыл бұрын
The video was very helpful, thank you :)
@CodingSimplified
@CodingSimplified 2 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@commando8822
@commando8822 2 жыл бұрын
Great explanation!!
@CodingSimplified
@CodingSimplified 2 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@divanshmahajan1769
@divanshmahajan1769 4 жыл бұрын
reverse the string and find lcs with original string..how does this soln work??
@TheRajmoney
@TheRajmoney 4 жыл бұрын
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.
@CodingSimplified
@CodingSimplified 4 жыл бұрын
Hi, I didn't get the question. Which String you're mentioning here. Could you please elaborate it, so that I can check it.
@TheRajmoney
@TheRajmoney 4 жыл бұрын
@@CodingSimplified how do you print the solution in string rather than returning just the length.
@TheRajmoney
@TheRajmoney 4 жыл бұрын
If longest palindromic subsequence is aba, How do we print that string from the table rather than returning just 3.
@surajgrandhi6742
@surajgrandhi6742 4 жыл бұрын
www.geeksforgeeks.org/print-longest-palindromic-subsequence/ you can see that here
@dheerajck3881
@dheerajck3881 4 жыл бұрын
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.ashoknaidu5787
@y.ashoknaidu5787 3 жыл бұрын
Well explained sir, ur great sir
@CodingSimplified
@CodingSimplified 2 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@AyushKumar-vh7pg
@AyushKumar-vh7pg 4 жыл бұрын
Sir why are we beginning the loop in bottom-up approach from end i didn't get that part
@CodingSimplified
@CodingSimplified 4 жыл бұрын
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.
@adarshgoyal5890
@adarshgoyal5890 4 жыл бұрын
Thank uu sir for this solution
@CodingSimplified
@CodingSimplified 4 жыл бұрын
Thanks Adarsh for your feedback. Keep Watching.
@arepallipriyanka3737
@arepallipriyanka3737 3 жыл бұрын
String is not printing how to print palindrome string?
@yasharthgupta9002
@yasharthgupta9002 2 жыл бұрын
class Solution { public String solve(String finalstr,int start,int end,String dp[][]){ if(start==end) return String.valueOf(finalstr.charAt(start)); if(start>end) return ""; if(dp[start][end]!=null) return dp[start][end]; if(finalstr.charAt(start)==finalstr.charAt(end)) return finalstr.charAt(start)+solve(finalstr,start+1,end-1,dp)+finalstr.charAt(end); String retvalue1 = solve(finalstr,start+1,end,dp); String retvalue2 = solve(finalstr,start,end-1,dp); if(retvalue1.length()>retvalue2.length()){ dp[start][end] = retvalue1; return retvalue1; } else{ dp[start][end] = retvalue2; return retvalue2; } } public int longestPalindromeSubseq(String s) { String dp[][] = new String[s.length()+1][s.length()+1]; String ans = solve(s,0,s.length()-1,dp); return ans.length(); } }
@urmyjudgementalfrndcinemah6748
@urmyjudgementalfrndcinemah6748 4 жыл бұрын
What is DP sir please reply
@CodingSimplified
@CodingSimplified 4 жыл бұрын
DP - Dynamic Programming is technique to solve coding problems.
DP-10: Longest Palindromic Substring
37:58
Coding Simplified
Рет қаралды 23 М.
DP - 6: Longest Common Subsequence
33:11
Coding Simplified
Рет қаралды 5 М.
Когда отец одевает ребёнка @JaySharon
00:16
История одного вокалиста
Рет қаралды 11 МЛН
Longest palindromic substring | Dynamic programming
15:21
Techdose
Рет қаралды 397 М.
Matrix - Find Number of Islands
17:09
Coding Simplified
Рет қаралды 7 М.
Parse JSON using Java
22:27
Coding Simplified
Рет қаралды 7 М.
DP - 20: Count of subsets with Sum equal to given Sum
21:53
Coding Simplified
Рет қаралды 19 М.
8 AI Tools That Will Make You Rich in 2025!
15:58
Aurelius Tjin
Рет қаралды 6 М.
How To Create A News Channel with AI | 2024
9:40
Website Learners
Рет қаралды 14 М.