Longest palindromic substring | Dynamic programming
This video explains how to find longest palindromic substring from a given string. This is a very frequently asked programming interview and coding round question. I have explained two techniques here. One is bruteforce by generating all possible substrings and checking if it is palindrome or not and storing the longest substring which is a palindrome found. My audio quality is bad due to damaged-mic so kindly bear for this video. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
CODE LINK: www.geeksforgeeks.org/longest...
Пікірлер: 479
🟣 JOIN our 𝐋𝐈𝐕𝐄 𝐢𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐭𝐫𝐚𝐢𝐧𝐢𝐧𝐠 𝐩𝐫𝐨𝐠𝐫𝐚𝐦 through whatsapp query: +91 8918633037 🔴 𝐂𝐡𝐞𝐜𝐤𝐨𝐮𝐭 𝐚𝐥𝐥 𝐨𝐮𝐫 𝐂𝐨𝐮𝐫𝐬𝐞𝐬: techdose.co.in/
Kudos for going through the whole input string instead of saying so on and so forth👍
@techdose4u
4 жыл бұрын
😂
@lionelmesssi2959
3 жыл бұрын
Bro tomorrow my exam is there , exam will consist of coding question in Java. Dynamic programming also there can you help me for exam .
@tekbssync5727
3 жыл бұрын
@@lionelmesssi2959 I don't think there will be any football match tomorrow .
@ganesh3761
2 жыл бұрын
@@tekbssync5727 😅😁
Fact : This guy alone is responsible for more placement offers than all college professors combined ! Change my mind
@techdose4u
4 жыл бұрын
Thanks
@ankitparashar8730
2 жыл бұрын
Professor kaha padhata Sab chutiyapa hai professor
@prajwalraut7480
Жыл бұрын
woahhhh today also this one is best explaination!!!!!!!!!!!!!!
@KevinLin45
Жыл бұрын
🧠 yelo change krlo :)
Please give this man a medal. Thank you for going through the whole string dry run
I knew from reading other explanations that it was the explanation itself that was hindering everyone including myself. You are so far the only person that actually explained how the dynamic approach works clearly.
What a great presentation and explanation ! You are just going frame by frame and bringing clarity all the way down deep! Keep doing such great videos for demystifying complex algos.
Thanks a million for making such an incredible explanation for a GFG code. Sometimes they have good codes, but no explanations or the explanations are not clear enough. This is just so well explained. All your videos are helping so many of us. Keep up the great work!
@techdose4u
3 жыл бұрын
Welcome :)
One of the best explanations for this question, for dp beginners🎉🍾 thanks a lot man💐👍
Bro this is the best explanation for the question and I finally understood it. Explaining is an art and making others understand is a superpower and you clearly has it. The video was crisp and so easy to follow. Just loved it. Pls keep making more videos. I know you might be busy with other stuff(I am sure u might be working for some top notch company and if not then you are surely going to be very soon) but pls keep making more videos.
@techdose4u
4 жыл бұрын
Yea sure :)
THE best explanation I’ve heard so far!!!
@techdose4u
4 жыл бұрын
:)
@lionelmesssi2959
3 жыл бұрын
Bro tomorrow my exam is there , exam will consist of coding question in Java. Dynamic programming also there can you help me for exam .
Excellent explanation ! As a newbie in dp i really was struggling to understand this concept but you made my life easier !!!
@techdose4u
3 жыл бұрын
Thanks
You are just explaining the whole concept with patience . thanku for clearing me this algo ,you are just my fav man❤️
@techdose4u
3 жыл бұрын
Welcome :)
Thank you for this, I've had trouble understanding this algorithm in other videos but this is the best explanation I've seen.
@techdose4u
3 жыл бұрын
Thanks :)
Thank you so much for the video! I hadn't truly understood the dynamic programming approach to the max palindrome substring problem until I watched your explanation. Thanks again!
@techdose4u
3 жыл бұрын
Welcome :)
New to DP. Was trying to get this approach for 2 hrs.Thanks alot for the explanation.Explained so well,no need to upload the code!
I watched lot of videos for this problem but no one explained like the way you explained.thank you sir
Now i know why your video is on the top when searched for this problem. Thanks for such good content.
I really love how you draw and go through the DP table. I don't see many people explain it that way and it can be very hard to visual or trace through at first. Thanks So much!
This is gold! Thank you for that clear explanation.. your DP series is the best out there!
@techdose4u
3 жыл бұрын
Welcome ❤️
Best Explanation ever ! Please continue doing this. Thank you :)
@techdose4u
4 жыл бұрын
Yea..... Thanks :)
No amount of thanks is ever going to repay the help you're lending us :) Thanks a tonne sir! Keep growing
I liked the way you explained this problem, best explanation I ever found for this problem.
@techdose4u
4 жыл бұрын
Thanks :)
really understood the concepts of DP with clarity. Never visualized like this before.. Thanks
Excellent explanation! Really appreciate that you went step by step even though it seemed tedious but it made it easy to follow.
@techdose4u
2 жыл бұрын
Thanks ☺️
Honestly, the best one explained this question
@techdose4u
4 жыл бұрын
Thanks :)
Quality content with best explanation compared to every other video, special thanks to you!!
good explanation! The reason this is a dp problem is that it has over lapping sub problems. For substring from index 1,5 we need to check if substr from index 2,4 is palindrome or not and for substr 0,6 we would not compute for substr 1,5. So it will take O(1) time instead of O(n).
It is really the best explanation I've ever seen in this subject! Thank you!
How you explain these things so clearly..... I must say you are very underrated
best video I have seen so far for understanding dp using a table
Thanks, TechDose, crisp n clear explanation, exactly what I was looking for, keep uploading!
@techdose4u
3 жыл бұрын
Thanks
Please, if possible, explain how you approach a problem and come up with solutions too as it'll help in developing our programming logic as well. Thanks for the great vids, keep em comin'! :)
@techdose4u
3 жыл бұрын
Sure :)
The only video that explains the DP matrix and each step of the algorithm. Thanks so much.
@techdose4u
4 жыл бұрын
Welcome :) I always explain the intuition and steps of dp matrix with reason for formulations.
Explained very well.. I have written the code using the instructions and it is working well strings of random sizes.. Thank you...
@techdose4u
4 жыл бұрын
Welcome :)
This channel is now becoming my fav channel,,, thanks for explaining the concept so easily .
@techdose4u
3 жыл бұрын
Welcome :)
@lionelmesssi2959
3 жыл бұрын
Bro tomorrow my exam is there , exam will consist of coding question in Java. Dynamic programming also there can you help me for exam .
finally got the concept behind the dynamic programming. Thank you
@techdose4u
4 жыл бұрын
Welcome :)
@lionelmesssi2959
3 жыл бұрын
Bro tomorrow my exam is there , exam will consist of coding question in Java. Dynamic programming also there can you help me for exam .
For length 3 also it is enough to check only if characters are equal, like length 2 as diagonal is always 1.
Can't explain how thankful I am for your explanations!
@techdose4u
3 жыл бұрын
Welcome :)
@lionelmesssi2959
3 жыл бұрын
Bro tomorrow my exam is there , exam will consist of coding question in Java. Dynamic programming also there can you help me for exam .
One of the best teachers found on KZread 👍🏻
@techdose4u
3 жыл бұрын
Thanks :)
This is the best expalantion for this question on youtube, thanks mate
Noone says that row is the starting pos and column ending. You just clear my doubt in first few minutes. Thank you again.
@techdose4u
3 жыл бұрын
Welcome :)
Thank you so much! It was crystal clear.
God-level explanation.!! If possible please keep these videos coming.
thank you Tech dose, I cracked google and linkedin. Learned a lot from your videos and explanations
@techdose4u
2 жыл бұрын
Congratulations 🤗💥🎉
what a great explanation! love your divide and conquer techniques
The best explanation so far!
I'm glad I found this channel.
@techdose4u
3 жыл бұрын
😊
Thanks , you get straight to the point continue like this
One of the best explanation for this problem.....Thanks bro...!!!!
If I had a teacher like you during college, I would never doubt myself that I can't learn DSA.
thanks for going through the whole string. Thank you for all your efforts 🙏
@techdose4u
3 жыл бұрын
Welcome :)
@lionelmesssi2959
3 жыл бұрын
Bro tomorrow my exam is there , exam will consist of coding question in Java. Dynamic programming also there can you help me for exam .
if there are more than one substring of the same length then how to return the substring which occurs first ( with the least starting index ) ?
Nice work. Hope to see your channel grow beyond numbers.
@techdose4u
4 жыл бұрын
Thanks buddy :)
outstanding explanation man !!! Keep up the great job !
Awesome buddy! Thanks for this
very good explanation and this was my first dp problem really understands really well
thanks for the explanation. was so good I didn't need help writing the code.
You must be really smart to come up with solutions like these
Thanks a lot, you've explained it really well. It's very helpful.
@techdose4u
3 жыл бұрын
Welcome :)
best explanation of this dp problem. Thank you so much🙏
Hello Tech Dose, can u please explain why this formula can't be apply for string length less than 3.
Best explanation ever!! Thank you sooo much :D
@techdose4u
4 жыл бұрын
Welcome :)
Thanks. Very useful. However, brute force can be done in O(n^2): for(0 through length of string-1) find the longest palindrome whose middle is in that position if(longer than the previous max) save the start and end indexes return substring at the saved start and end indexes
@geeteshchallur1034
2 жыл бұрын
So how is dp appoach better than this approach?
wow this is gold. such a great solution. Thanks a ton. i usually approach dp problem with rec first then memoization then tabulaiton. bt this is more like concrete tabulation solutiion.
Perfect Explanation. Thank you!!
@techdose4u
4 жыл бұрын
Welcome :)
Sir I didn't understand how to loop through the array, first we checked for (0,2) then for (1,3) and then for (2,4)... How to increment both I and j and after reaching end for j , we again set set I to some other index. How and which loops should be used?
Really good explanation @techdose. i feel more confident with DP now
Sir...how beautifully u explained the logic...Thank you
@techdose4u
3 жыл бұрын
Welcome :)
Awesome explanation, finally I understood, thanks.
@techdose4u
4 жыл бұрын
Welcome :)
Very clearly explained . Thanks for helping me out brother.
@techdose4u
4 жыл бұрын
Welcome
Flawless explanation!!. Thank You!
@techdose4u
4 жыл бұрын
Welcome :)
Your explaining skill is mind-blowing 😁
This was great !! Thanks for helping me understand this one
@techdose4u
3 жыл бұрын
Welcome :)
the best explanation i found
The BEST explanation ...tqsm
That was a brilliant Explaination...
Could not find better explanation than this.
He made this problem a cake walk. Thanks man.
@techdose4u
2 жыл бұрын
Welcome 😀
@ahasunos5914
2 жыл бұрын
@@techdose4u 🙌
any idea about how t print the String, max length will generate in dp[0][s.length()-1]
One of the best explanations I've come across! Do you have a video for O(n) complexity as well?
@techdose4u
4 жыл бұрын
No, till now I have not made any video on manacher's algo.
Amazing video and nicely explained. Great job
@techdose4u
4 жыл бұрын
Thanks :)
Thanks for simple explanation
In fact, we could solve it in O(N2) time without any extra space. We observe that a palindrome mirrors around its center. Therefore, a palindrome can be expanded from its center, and there are only 2N-1 such centers. You might be asking why there are 2N-1 but not N centers? The reason is that the center of a palindrome can be in between two letters. Such palindromes have even number of letters (such as “abba”) and their center are between the two ‘b’s. Since expanding a palindrome around its center could take O(N) time, the overall complexity is O(N2). Source : InterviewBit
@techdose4u
4 жыл бұрын
Nice :)
What tool are you using to draw on screen?
Well explained ✨😃Thankyou..
you have the best dynamic programming playlist ever
@techdose4u
3 жыл бұрын
Thanks
will you please make a conceptual video on manacher's algorithm with pseudocode, i am waiting for the same, thanku
Thx for this Video man.
very nice explanation. thank you
Can someone explain on what basis did we consider the longest palindrome from 2 to 7 after filling the table?
Is there any space optimized method too ?
Nicely explained! Thank you!
@techdose4u
2 жыл бұрын
Welcome 😀
Such a great teacher 🙏🙏🙏🙏🙏
This was great, sir. Thank you.
Sir can you please explain how do I iterate the loop though ?
Java solution | DP thank you for the great explanation too :) 🔥 public String longestPalindrome(String s) { int n = s.length(); if (n == 1) return s; // dp[1][2] represents substring of s in range [1,2] inclusive is palindrome or not // 1 indicates palindrome in dp array and 0 represents not a palindrome int[][] dp = new int[n][n]; int start = 0, end = 0; // index of answer in s for (int i = 0; i // for upper triangular matrix for (int j = i; j >= 0; j--) { // end position in s if (i == j) dp[i][j] = 1; else if (i - j == 1) { // for substring of length 2 in upper traingular matrix if (s.charAt(i) == s.charAt(j)) dp[i][j] = 1; } // check border character and substring inside current border indicated by i and j else if (s.charAt(i) == s.charAt(j) && dp[i - 1][j + 1] == 1) { dp[i][j] = 1; } // tracking maximum length for substring with index in s if (dp[i][j] == 1 && i - j > end - start) { start = j; end = i; } } } return s.substring(start, end + 1); }
Thank u so much sir.....You explained in a wonderful way!!!
@techdose4u
3 жыл бұрын
Thanks
This was asked today for our placement test. I was shocked. BTW it was for an SDE internship for 18k/month
Thank you bro. Awesome explanation 👏
@techdose4u
4 жыл бұрын
Thanks :)
Very nice explanation, thank you so much!!!
@techdose4u
3 жыл бұрын
Welcome :)