Longest Palindromic Subsequence

  Рет қаралды 317,673

Tushar Roy - Coding Made Simple

Tushar Roy - Coding Made Simple

Күн бұрын

Пікірлер: 243
@akhilguptavibrantjava
@akhilguptavibrantjava 9 жыл бұрын
Best videos ever on Dynamic Programming
@ShivangiSingh-wc3gk
@ShivangiSingh-wc3gk 7 жыл бұрын
Can you explain how you think about such stuff. I understand how things are working but I find it hard to make up the thing myself.
@YiboHuang
@YiboHuang 7 жыл бұрын
Making up the thing is really hard, he probably didn't come up with it himself just saying.
@rohitkumarkhatri2203
@rohitkumarkhatri2203 7 жыл бұрын
No No, once ur level reaches at that point and u r in touch with these things for little longer, it starts happening that u can come up with solution. take very easier probs of DP. u will be able to make solution ur self, similarly solve most of them, move to hard DP prbs. after some solution u can solve ur self.. Tushar solved this himself or not, but he must be capable of making solutions himself.
@unboxordinary
@unboxordinary 7 жыл бұрын
if you guys don't know he worked at apple, aws, amazon www.linkedin.com/in/tushar-roy-4351091a/
@nehaparmar497
@nehaparmar497 7 жыл бұрын
If you look up his solutions in GitHub, he has very clearly specified the links in the comments section at the top, to all the sites he referred.
@sagardafle
@sagardafle 7 жыл бұрын
The answer lies at 0:55 : "How do we solve this ? Yes, we will use Dynamic Programming!"
@sonali2090
@sonali2090 2 жыл бұрын
Thanks Tushar.. Your videos helped me land a job in Amazon six years back. You are a very good teacher. :) Also, it will be good if you can explain top down approach at the end or the beginning. :)
@amirkeibi2396
@amirkeibi2396 7 жыл бұрын
Thanks. A colleague recently send me a link to this video and asked me a couple of questions about it and DP in general. I think it would've helped if it was explained for example why you're looking at the max of 2 numbers to determine the 3rd one (the recursive nature of DP). It's only clear to someone who has solved DP problems.
@rheumaticharm9551
@rheumaticharm9551 3 жыл бұрын
Wow it's been 4 yrs but still I'll try to solve ur issue. The reason we are checking the max is because the matrix that we are building is designed in a way to give answers of subsequence of 1 lesser lenght in its adjacent spaces. And since WE NEED THE LONGEST PALINDROMIC SUBSEQUENCE HENCE we will consider the bigger one only. Although u can consider the other one and that will also lead u to some PALINDROMIC SUBSEQUENCE but it won't be the longest.
@surajpant2150
@surajpant2150 7 жыл бұрын
This man should be in Matrix movie... because he solves all DP problem using matrix😂 take it as compliment bro... thank you so much for easy explanation 👍👍
@NareshKumar-dw9xp
@NareshKumar-dw9xp 4 жыл бұрын
I have learned whole DP from you. Trust me, this guy taught everything by just matrix.
@cypherllc7297
@cypherllc7297 4 жыл бұрын
Are you able to do new DP questions after learning from here?
@NareshKumar-dw9xp
@NareshKumar-dw9xp 4 жыл бұрын
@@cypherllc7297 not completely but ys i have a good idea.
@cypherllc7297
@cypherllc7297 4 жыл бұрын
@@NareshKumar-dw9xp should we memorize algorithm approach?
@NareshKumar-dw9xp
@NareshKumar-dw9xp 4 жыл бұрын
@@cypherllc7297 No , just do practice as much as you can . As you'll practice a lot , your mind will automatically prepared be when you will see new dp questions. But first, you need to train your mind.
@blasttrash
@blasttrash 3 жыл бұрын
actually dont follow tushar approaches. They are bad. Who draws a dp table right away? you don't even know if its a dp problem first, you don't even know the dp formula first, you don't even know the return value first and so forth. Instead check aditya verma, andrey grehov, and mit videos for a better approach. Unless we come up with dp formula, dp questions are very hard. And for us to come up with dp formula in an interview you need to byheart a lot of patterns(a lot of people say its not needed, but this is exactly what they are doing unknowingly).
@fk121276
@fk121276 3 жыл бұрын
Very very nicely explained. Could you also explain a bit about the Time and Space Complexity of this algorithm.
@tapanchudasama6656
@tapanchudasama6656 4 жыл бұрын
The most important thing to code a DP problem is to understand why DP needs to be implemented in the first place. Then you need to come up with a recursive approach followed by a top-down memoization approach and then you know that okay, I can do this in the bottom-up approach too. Your videos can be a whole lot better if you could explain these concepts instead of straight away jumping to bottom-up DP. I'd recommend watching Aditya Verma's DP playlist for those who'd like to understand DP thoroughly. There are some 50 videos in that playlist. And's its pure gold.
@2708meghu
@2708meghu 7 жыл бұрын
Thank you soo much....!!! U made Dynamic Programming easy!!! Further we would expect the same for NP-Completeness problem. It is very hard to understand NPC problems and to solve them
@sahi145
@sahi145 8 жыл бұрын
Thanks a lot Tushar. Wonderful video. Helped a lot!!
@7810
@7810 2 жыл бұрын
Clear explanation. Thanks for the sharing!
@madnorbi
@madnorbi 9 жыл бұрын
Kudos to your efforts. Keep up. Ideas to some nice followups: running time, memory consumption (also considering trade-offs, we can answer just the length with O(N) memory) actual code why does this specific recursion formula work (why don't we loose by choosing greedily the matching pair)
@harshtekriwal131
@harshtekriwal131 4 жыл бұрын
Better solution is, Revese the string and apply longest common subsequence between the original one and the reversed one.
@abhishekjiwankar1
@abhishekjiwankar1 3 жыл бұрын
there are scenario's where the reverse LCS method fails. This is better solution
@SHUBHAMKUMAR-xh7dk
@SHUBHAMKUMAR-xh7dk 3 жыл бұрын
@@abhishekjiwankar1 can you give a testcase for the same.
@abhishekjiwankar1
@abhishekjiwankar1 3 жыл бұрын
@@SHUBHAMKUMAR-xh7dk Sure.. here is one.. wcipeg.com/wiki/Longest_palindromic_subsequence#LCS-based_approach It gives wrong answer if there are multiple longest sub sequence
@blasttrash
@blasttrash 3 жыл бұрын
@@abhishekjiwankar1 nice to know, but the article you mentioned only fails when asked to find the said LPS strings. If we only care about max length of palindrome subsequence, then I guess LCS and reverse approach works fine.
@abhishekjiwankar1
@abhishekjiwankar1 3 жыл бұрын
@@blasttrash that is correct
@himanshuarora1907
@himanshuarora1907 8 жыл бұрын
We could have taken the reverse and apply LCS to it. Is there anything wrong with that approach?
@sehgaldam121
@sehgaldam121 8 жыл бұрын
+himanshu arora Yes you can do that and get the result in O(N^2)
@shubhamraj7524
@shubhamraj7524 6 жыл бұрын
epic man!! this actually works ...
@shreejitnair2174
@shreejitnair2174 6 жыл бұрын
The bottom up DP soluton also uses additional space right? I am not sure if any DP problem without memoizing and having additional memory to store past events, please correct me if m wrong.
@ashwiniyengar8657
@ashwiniyengar8657 6 жыл бұрын
I dont think that would work all the cases, here is an example where it wont work, 'aacdefcaa' -> here if we go by reverse and then LCS answer comes out to 3 i.e. aac or caa whereas the actual answer is 2 i.e. aa
@tanzzzzz225
@tanzzzzz225 5 жыл бұрын
@@ashwiniyengar8657 the answer would be 'aca', 'ada', 'aea', ... and so one but the longest is 3. So the answer is correct
@shivaamidala
@shivaamidala 7 жыл бұрын
querying the longest palidromic sequence is not clear. you explained which to pick not how are they picked
@TheElementFive
@TheElementFive 2 жыл бұрын
“Here, they are same. Let’s see how it’s different.” I don’t know why but that cracked me up lol
@rancui201
@rancui201 3 жыл бұрын
your video never fails me down!!
@utuk123
@utuk123 8 жыл бұрын
Awesome Explanation.Thanks Tushar Sir.
@张莹-f4v
@张莹-f4v 2 жыл бұрын
Thank you, your explanation is very clear
@niharikapatil902
@niharikapatil902 3 жыл бұрын
Thanks for this amazing video!
@qiaogao4251
@qiaogao4251 3 жыл бұрын
Thanks for sharing this solution. It's quite clear!
@thePrinceOfPurpose
@thePrinceOfPurpose 5 жыл бұрын
Here is my solution: var s = "ABBBCCCDDDAE"; var out = findLongestString(s); console.log(out); function findLongestString(str){ var lookup = {}; var max = 0; var start = 0; if(str.length == 0){ return 0; } if(str.length == 1){ return 1; } for(i = 0; i < str.length; i++){ console.log(lookup); var c = s[i]; if(lookup[c] && lookup[c] >= start){ start = lookup[c] + 1; } lookup[c] = i; max = Math.max(max, i - start + 1); } return max; } Javascript style ;). Thank you for the helpful video.
@notreadyforanything
@notreadyforanything 6 жыл бұрын
Thanks for videos such as this. It helps a lot for self-learning.
@idiot7leon
@idiot7leon 4 жыл бұрын
Thanks, Tushar. Super clear!
@KansasFashion
@KansasFashion 3 жыл бұрын
You are so good man, Thank you so much for teaching us that!
@tanzzzzz225
@tanzzzzz225 5 жыл бұрын
ah, this one is tough compared to the other videos i hv seen so far
@KamilAliAgrawala
@KamilAliAgrawala 9 жыл бұрын
Great video Tushar. Just a tip Label the matrix axis. I did my i,j the other way around and it tripped me up for a long time. Thanks
@hirenpatel3462
@hirenpatel3462 11 ай бұрын
one other way to solve the above problem using reverse of string and Dynamic programming (LCS)
@pastacork
@pastacork 8 жыл бұрын
Tushar, thank you very much for your tutorials.
@rsearchyt
@rsearchyt 9 жыл бұрын
Very helpful. Thx for posting video Tusar.
@devdev19
@devdev19 3 жыл бұрын
Really great explanation
@rajanrajendran9329
@rajanrajendran9329 9 жыл бұрын
You are another Sal Khan! Thanks Tushar!
@ShankaranG
@ShankaranG 9 жыл бұрын
very helpful. Thanks for posting the videos
@rakeshroshan829
@rakeshroshan829 5 жыл бұрын
Thanks Tushar , great explanation
@czsokola
@czsokola 9 жыл бұрын
One should mention the second possible base case. If your length is 2 and first letter is the same as the last (second) letter, then you get 2 + longestPalindrom(i+1; j-1) -> so you should define: When substring start is greater than its end, longest palindrom is 0. [This is the only possibility how to bring even numbers into result.]
@MadHolms
@MadHolms 10 ай бұрын
I finally understood it, thx!
@shivamchauhan2673
@shivamchauhan2673 4 жыл бұрын
Bro, do please explain the logic behind what you are doing and also what the rows and columns signify in the matrix. Such ridiculous time waste. We are here to learn not, to just memorize the approach. Also the recursion formula is wrong: checkout for "bebeed" or simply take "aa" it will result in 3.
@vishalmishra1937
@vishalmishra1937 4 жыл бұрын
I guess correct part for if is Dp[I][j]=2+dp[i+1 ][j-1]
@Relaxingmusic-tw4qn
@Relaxingmusic-tw4qn 4 жыл бұрын
bhai adita verma bol ke ek channel hae wo approch sikhata hae, uska ye wala dekh sochna kaisae hae sikhaega banda kzbin.info/www/bejne/raaygIJ3id-Sf6M
@HXYZZZ
@HXYZZZ 3 жыл бұрын
it is simply: row index represents start index of the string. column index represents end index of the string. when you are looking at full string ie., index 0 to 5, you are getting the result of previous comparison from index 1 to 4. if the value of this is 2 , then result will be 4 + current char match result for indexes 0 and 5. hope it helps.
@aparnagopal5201
@aparnagopal5201 3 жыл бұрын
LPS of a string is the same as the LCS between a string and it's reverse. Same time and space complexity
@jb25379
@jb25379 3 жыл бұрын
Yes, I prefer this approach as well. Fewer things to remember.
@ManrajGrover
@ManrajGrover 9 жыл бұрын
Thank you so much for this wonderful explanation. :) Please continue to make such tutorials. Would appreciate follow up practice problems along with this.
@ManrajGrover
@ManrajGrover 9 жыл бұрын
*****​​ No. I mean suggest some problems using this concept on Online Judges like SPOJ or CodeChef for practice. :) 
@piyushjoshi5187
@piyushjoshi5187 8 жыл бұрын
Thankyou Tushar.... great... U R awesome...
@bharath_v
@bharath_v 8 жыл бұрын
Tushar, You are amazing!👌
@kishorebatta7395
@kishorebatta7395 5 жыл бұрын
@Tushar - You are directly going to solving part. But please explain how does this problem satisfies dynamic programming properties. Without that it is highly difficult to solve other problems.
@pagliacc1
@pagliacc1 8 жыл бұрын
I have to mute or ff whenever you try to draw or erase something. The noise was just breathtaking.
@mayankkumarthakur
@mayankkumarthakur 2 жыл бұрын
Great video as always. Tushar's videos really helped me to build my basic especially with dp and graphs. In the github code shared by him, he is filling every upper half cell in dp matrix. But, many times we may not need to fill all the cells. So, I think implementing it using recursion is a little faster for multiple testcases. Hope you have a good day.
@malharjajoo7393
@malharjajoo7393 8 жыл бұрын
The bottom up solution for this question will be 2 for loops but note that unlike the usual case , i will not start from 0 , instead from max value and towards 0
@aviralverma1701
@aviralverma1701 6 жыл бұрын
Awesome tushar!
@gdthegreat
@gdthegreat 5 жыл бұрын
Nice videos sir. Why are you not active on KZbin since 2 years? Your content is great.
@ameyapatil1139
@ameyapatil1139 7 жыл бұрын
Brilliant explanation !
@vatsayaynbinay160
@vatsayaynbinay160 4 жыл бұрын
actually there is no need to add $ . This works just fine for even sized subsequence as well
@code-at-amrita
@code-at-amrita 8 жыл бұрын
Nice video. Thanks for your clear explanation. God bless you Tushar.
@saurabhsawant6487
@saurabhsawant6487 8 жыл бұрын
Nice Explanation ! very helpful. Thanks for uploading. If possible please upload some videos about how to approach such problems.(in short how to derive dp strategy )
@lalitdudheria2580
@lalitdudheria2580 9 жыл бұрын
I had to login to thank you. Your videos are great :)
@priyankpatel8034
@priyankpatel8034 4 жыл бұрын
Great explanation 👍 thanks
@anuragsandhu9590
@anuragsandhu9590 7 жыл бұрын
LANGUAGE USED IS JAVA class Solution {static int z1[]=new int[100]; static int z=0; static String q[]=new String [100]; public static void main(String[] args) { String ss="anuragnitinrotavatorsindhuracecar"; int n=ss.length(); char s[]=new char[100]; s=ss.toCharArray(); for (int i=0;i
@lexicongem
@lexicongem 9 жыл бұрын
Awesome explanation!!!!
@anuveshkothari
@anuveshkothari 9 жыл бұрын
understands the video but couldn't understand the implementation (your code in github) how are you calculating the dynamic array values
@anuveshkothari
@anuveshkothari 9 жыл бұрын
two for loops that you are using
@ShyamRonline
@ShyamRonline 9 жыл бұрын
anuvesh kothari Try this gist.github.com/bourneagain/fb7cc841112e24cce19c which is inline with the video explanation
@bhavyasharma1064
@bhavyasharma1064 9 жыл бұрын
Thanks for these videos....very helpful....:)
@user-zh6jt8tl9y
@user-zh6jt8tl9y 4 жыл бұрын
This makes no sense. You don't explain why we're taking the max of the two substrings of the window.
@Vidur11
@Vidur11 4 жыл бұрын
It makes sense. Suppose you have a substring "bdb". The total length of the palindromic subsequence(ps) bdb would be the cumulative sum of ps "bd"(1, since either b or either d alone) + length of ps "db"(1 since either b or d alone) + 2(to account for the two b's at the ends of the subsequence). In the case of bdb, we are taking the 2 b's and singular d which results in a length of 3.
@Alwaysiamcaesar
@Alwaysiamcaesar 4 жыл бұрын
@@Vidur11 That doesn't make sense for input "agbdbaa". By that logic "agbdba" = 5, "gbdbaa" = 3, and "gbdba" = 3, so sum = 5 + 3 + 3 = 11 which is not the answer. The answer is supposed to be 5...
@Vidur11
@Vidur11 4 жыл бұрын
@@Alwaysiamcaesar First of all, i mentioned that the total length of the ps is equal to the total length of it's subsequent "inner" palindromic subsequences. That means you have to look inside the string recursively. In your case of "agbdbaa", we know that "bdb" has a string length of 3. Taking L=6, we see that a and a are equal so we can add these two to the palindromic subsequence. Now contained within "aa" is the subsequence "bdb" of length 3. So the total length is 3 + 2 = 5 ("abdba"). I think you are making the mistake of taking the summation of all the substrings within the given substring, when in reality you must take only the summation of the valid palindromic subsequences within a substring.
@shobhitsrivastava4496
@shobhitsrivastava4496 5 жыл бұрын
May god bless you, sir
@KansasFashion
@KansasFashion 3 жыл бұрын
Dude, I love you so much!
@lac2275
@lac2275 4 жыл бұрын
Well done bro!
@HarishAmarnath
@HarishAmarnath 4 жыл бұрын
no explaination on why we choose dynamic programming and no explaination of how to think about some question ... "yes we ll use dynamic programming " is all we got
@rantlord8373
@rantlord8373 4 жыл бұрын
Recursion with repeated data => use dynamic programming. Clear your concepts before attempting such problems.
@babybear-hq9yd
@babybear-hq9yd 4 жыл бұрын
@Harish I posted an extended comment here recently explaining how to go about thinking up the solution, before diving into the DP code! Have a look :)
@algoquest6741
@algoquest6741 8 жыл бұрын
Is there a problem in the logic when two similar chars are present together? Consider this example input string: "AABCDB" I expect the output to be 4 (AABB) - but according to the logic presented here it says 3. Am I missing something?
@ritwikdas9316
@ritwikdas9316 8 жыл бұрын
+algoquest Dude AABB is not a palindrome
@algoquest6741
@algoquest6741 8 жыл бұрын
+Ritwik Das My bad. Apologize for missing that. Excellent videos +tusharroy2525
@04pradeep
@04pradeep 8 жыл бұрын
Hi Tushar, its not clear in the video why you choose to create a matrix and fill it up in a certain way. When I trace it in paper it became clear for this problem,. For example in this video I was not able to understand why the values in the left of diagonal was left empty. I like your dynamic programming videos. I have written this comment in the interest of your videos becoming clearer and getting more views.
@studyonline3236
@studyonline3236 5 жыл бұрын
Hello Tushar , there's a case where the above code throws an error, when the length is 2 and the characters MATCH, we look diagonally downwards (According to that code), which would be empty . So when L==2 && inp(i)==inp(j) T[i][j]=2;
@avleenmehal4648
@avleenmehal4648 4 жыл бұрын
it will not be empty but with a value of zeross the whole matrix is filled with zeros unless changed
@yanivgardi9028
@yanivgardi9028 8 жыл бұрын
Thanks Tushar. can we generalize the solution by initializing the matrix in T[x][x-1] = -1 in that way, when dealing with length=1 we can follow the formula, without corner case for length 1. meaning: since string[start]==string[end] T[start][end] = 2 + max[T[start+1][end], T[start][end-1]) = 2+max(-1, -1) = 1
@amadousallah6634
@amadousallah6634 9 жыл бұрын
Great explanation
@rodrigoceccatodefreitas1656
@rodrigoceccatodefreitas1656 6 жыл бұрын
You are amazing man!
@mouiadhani5167
@mouiadhani5167 9 жыл бұрын
Thank you man...That was helpful!
@MrThepratik
@MrThepratik 4 жыл бұрын
very well explained.
@ashwiniyengar8657
@ashwiniyengar8657 6 жыл бұрын
Can you explain how this would work for a input string like this 'aacdefcaa' where the answer should be 2 'aa', but i am not getting the same result with this method?
@alfonsocanady7564
@alfonsocanady7564 6 жыл бұрын
actually i think the answer should be aacdcaa since it's the longest non contiguous palindrone. It actually doesn't have to be aacdcaa it could be aacecaa or aacfcaa
@nimishbajaj3815
@nimishbajaj3815 8 жыл бұрын
Thanks Tushar, if someone really wants to be very good in Programming which book/s do you recommend ?
@osamaalkhodairy3155
@osamaalkhodairy3155 7 жыл бұрын
In my opinion begin with Competitive Programmer HandBook then CLRS ( *optional* ) then Competitive Programming 3 (CP3), hope it will help ^_^.
@prashantpatel1314
@prashantpatel1314 6 жыл бұрын
www.amazon.in/Algorithms-Unlocked-Thomas-H-Cormen/dp/0262518805/ref=as_li_ss_tl?ie=UTF8&linkCode=ll1&tag=freembastuff-21&linkId=e0c92577108ad9bec0651d4541572992
@sonali9696
@sonali9696 3 жыл бұрын
Can't we do it like longest subsequence problem with first string as input A and second being reverse(A) - let's call it B. Here if A[i] == B[j] then dp[i][j] = dp[i-1][j-1] + 1. And if not equal then dp[i][j] = max(dp[i-1][j], dp[i][j-1]). I tried it with some examples and it works. I feel like you are essentially doing the same thing just in a more complicated manner. Please someone correct me if I am wrong in this method.
@findingMyself.25yearsago
@findingMyself.25yearsago 2 жыл бұрын
Hi sonali, It won't work.... Try this example "aacabdkacaa" reverse would be "aacakdbacaa" Common subsequence would be aacakacaa But here the answer would be "aca"
@winterheat
@winterheat 3 жыл бұрын
how come bbbab is 4, for bbbb? Isn't bbabb ok too? So it is 5. Does it mean substring as in "you can delete any character"? Somewhat unclear
@oxana602
@oxana602 7 жыл бұрын
Tushar, thank you!!!
@manavmohata1240
@manavmohata1240 4 жыл бұрын
You can just make a new string which is the reverse of the given string and find the longest common subsequence instead of this.
@sumitchoube3875
@sumitchoube3875 4 жыл бұрын
I also thought same approach
@ujurak3899
@ujurak3899 4 жыл бұрын
This may work for smaller test cases, but you will get TLE on longer strings with this approach.
@nerocide1111
@nerocide1111 6 жыл бұрын
I think an easier approach to this would be to use the OPT function
@nerocide1111
@nerocide1111 6 жыл бұрын
cool shades
@junzhuang4923
@junzhuang4923 5 жыл бұрын
Thanks for your clear explanation on this table. Great.
@xxxyyy8288
@xxxyyy8288 7 жыл бұрын
look really happy this day
@vipulsharma1897
@vipulsharma1897 5 жыл бұрын
great work bro
@edwinchen7729
@edwinchen7729 5 жыл бұрын
that was a quick and clear explanation, thanks a lot!!!
@animatedzombie64
@animatedzombie64 3 жыл бұрын
here is the recurrent relation, so you can think of dp solution f(i, n) -> if Ci == Cn : 2 + f(i+1, n-1); 2 for two characters else: max( f(i+1, n), f(i, n-1) );
@florakunjumon9180
@florakunjumon9180 2 жыл бұрын
Thank you so much!
@joeycopperson
@joeycopperson 7 жыл бұрын
Nice explaination :)
@MarcosCastroSouza
@MarcosCastroSouza 9 жыл бұрын
thanks Tushar, well explained, have you participated in programming competitions?
@devesh87
@devesh87 9 жыл бұрын
can we extend this solution for longest palindromic substring?
@aridokmecian
@aridokmecian 5 жыл бұрын
Could we run Lowest Common Subsequence with original string and reverse of original string to receive the same answer?
@GurudevKumar_NIT-A
@GurudevKumar_NIT-A 5 жыл бұрын
Yeah we can get correct result using this approach as well
@ashwinap6995
@ashwinap6995 8 жыл бұрын
Hello +Tushar , How to find all possible palindromic subsequence in this string ?
@piyushsrivastava9476
@piyushsrivastava9476 9 жыл бұрын
excellent work.
@zemalex89
@zemalex89 8 жыл бұрын
this is not working for: abcggfcab, by what you shown the number always will be odd
@nafisfaiyaz7543
@nafisfaiyaz7543 4 жыл бұрын
It works. Maybe you made a mistake in implementation. Check it out: pastebin.com/s6Cpbv6g
@expeng5861
@expeng5861 5 жыл бұрын
great video
@akhilguptavibrantjava
@akhilguptavibrantjava 8 жыл бұрын
A small doubt :) While finding the characters that make the palindromic Sequence why do we go diaganally? I Guess Same result we can achieve if we go horizontally in backward direction and considering the character whenever the count becomes 2 less than the previous value.
@rheumaticharm9551
@rheumaticharm9551 3 жыл бұрын
Becuase we are checking string according to lenght. For example at matrix[0][0] we are checking the string[0] which is char 'a'. Hence it is not possible to do horizontally if ur still using the same technique. Whole logic needs tk be changed in a totally different way.
@minhluong4604
@minhluong4604 7 жыл бұрын
How can i get the actual subsequence from this algorithm ?
@halojustin01234567
@halojustin01234567 6 жыл бұрын
Do you initialize len 1, 2 and 3 entries first and then calculate others based on that
@suyogkatekar8548
@suyogkatekar8548 8 жыл бұрын
This is pure gold
@abhaydoke09
@abhaydoke09 7 жыл бұрын
Most of the time board is not visible. Good explanation!!
@um4720
@um4720 4 жыл бұрын
Can you please share the code to print the LPS?
@tushargupta2356
@tushargupta2356 5 жыл бұрын
should we first make the complete table before coding the problem in a competition?
@dhriajbhandari
@dhriajbhandari 8 жыл бұрын
According to this: en.wikipedia.org/wiki/Longest_palindromic_substring . The palindrome needs to a continous substring In the above example, g breaks the palindrome abdba. So the answer should be 'bdb'. Is that right?
Longest Palindromic Substring Manacher's Algorithm
16:46
Tushar Roy - Coding Made Simple
Рет қаралды 346 М.
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН
Find The Longest Increasing Subsequence - Dynamic Programming Fundamentals
19:21
26  Longest Palindromic Subsequence
12:46
Aditya Verma
Рет қаралды 220 М.
Longest Palindromic Subsequence - Leetcode 516 - Python
18:04
NeetCodeIO
Рет қаралды 29 М.
Longest Common Subsequence Dynamic Programming : Interview question
19:52
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 55 М.
LeetCode 5.  Longest Palindromic Substring (Algorithm Explained)
14:40
Longest palindromic substring | Dynamic programming
15:21
Techdose
Рет қаралды 404 М.
Longest Common Subsequence
7:55
Tushar Roy - Coding Made Simple
Рет қаралды 775 М.
Maximum Sum Increasing Subsequence Dynamic Programming
8:30
Tushar Roy - Coding Made Simple
Рет қаралды 82 М.
Leetcode problem Longest Palindromic Substring (two solutions)
25:19
Errichto Algorithms
Рет қаралды 164 М.
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН