Leetcode problem Longest Palindromic Substring (two solutions)

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


Subscribe for more educational videos on algorithms, coding interviews and competitive programming.

Рекомендации по теме
Комментарии
Автор

Your first statement made me crying for 2 hours straight

stanshen
Автор

I love your tutorials, how you go from the naive solution to the optimized one

youssefmuhamad
Автор

This is the beauty when someone red on codeforces solves interview problems. It was so easy for you Errichto, but for the sake of your audience you explained it thoroughly. Thanks :)

ashutoshmaheshwari
Автор

I just love how you go from the simplest to the most optimized solution and the way you explain the process for optimizing the code.

harshitmittal
Автор

Wow, no ads in any video.... This man is a legend

varunv
Автор

The small c++ optimizations you mentioned in this video will be really helpful for me while coding. Thanks for putting out content like these

BigFatSandwitch
Автор

Thank you brother from another mother, everyone on YouTube showing the code of optimised approach,
Only you showed the brute force

kettlebell_only
Автор

Love this! Because this is a simpler problem (comparing others in this channel) I could understand the proccess and I've got so many things to learn. Thank you!

kaiovieira
Автор

One Errichto video teach you a lot of extra things along with the actual solution.

Akshaykumar-blok
Автор

Great stuff, Errichto! There are far more successful YouTubers with a greater following. BUT I think you're way ahead of them in terms of material and quality content. Would love to see more videos like this. I think at the moment you're far under rated. Keep up the good work! 😀

dcodernz
Автор

My first thought was hashing.

It's possible to hash the string and hash the reversed string.

Then to find the longest palindrome, we can for every mid point (or double mid points for even length palindromes) iterate over it's prefixes and suffixes and compare them using hashes.

Now add binary search and we don't have to do that for every pref/suf length and just for O(logn) of them.

If I am not mistaken the total complexity would be O(n*logn)

sanfarans
Автор

Thanks for the explanation. I came to watch your video after I solved the problem myself. I was not disappointed because you explored many options. For N^2 time complexity what I did was reversed the original string and used longest common substring between the original string and the reversed string. I got an edge case where it was finding strings of length 2 to be palindrome even if they were not.

ShreyanGoswami
Автор

errichto makes me wanna leave programming and love programming at a same time..

RaGa_BABA
Автор

I wish you covered the Manacher's algorithm as well.

wedding_photography
Автор

Loved it, good job. One small observation, the string is a degenerate case for time in your algorithm. Instead of iterating mid in 0, 1, 2, 3, 4, you could iterate mid in n/2, n/2 + 1, n/2 - 1, n/2 + 2, n/2 - 2, ....
Then just check if mid is far enough away from the edges to make a possible new best. That puts you really close to O(n) .

CarrotCakeMake
Автор

You are awesooome, thank you. I love that you first write the naive solution and then explain and improve the code bit by bit :3

shahriardhruvo
Автор

I really appreciate your videos. I think the intuition behind how you derive the solution is outstanding. Helps a lot to understand how you came develop an approach.

achavan
Автор

I loved your way of breaking down the problem and gradually moving towards more optimized version. Would love your input on codechef problems from long challenge, cook off, lunchtime and various other categories of problem.

muskanagarwal
Автор

Thank you so much for these Leetcode tutorials. Absoultely love them !

atibhiagrawal
Автор

Your explanations of problems are awesome going from bruteforce approach to

raushankumarraman