LeetCode 234: Palindrome Linked List - Interview Prep Ep 63

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


⭐ Support my channel and connect with me:

Solutions explained:
1. We'll use the two pointer technique: to move slow pointer to the middle of the list and fast pointer towards the end;
2. Then we'll reverse the second half of the list and start the side by side comparison.

Time: O(n)
Space: O(1)

// TOOLS THAT I USE:

// MY FAVORITE BOOKS:

My ENTIRE Programming Equipment and Computer Science Bookshelf:

And make sure you subscribe to my channel!

Your comments/thoughts/questions/advice will be greatly appreciated!

#softwareengineering #leetcode #algorithms #coding #interview #SDE #SWE #SiliconValley #programming #datastructures
Рекомендации по теме
Комментарии
Автор

Thanks for the clear code and explanation! Also glad to see complexities get mentioned at the end as well.

vaibhavm
Автор

I'm very surprised that your channel doesn't have more views than it does yet... keep up the awesome work!!!

wheresthebeach
Автор

I watched lot's of video about this topic every body is mixing reversed in same code but you made a separate method for reversed that made to understand this problem,
Love your approach 💞

saddam_khan_abuzaid
Автор

I watched a couple of videos from different channels with the same problem but your video was the best. Thank you :)

ehsanhosseini
Автор

Clear and awesome explanation, keep it up!

jerryyang
Автор

What if its a odd string ? There would be an extra element

pallav
Автор

Great video I wish it was clearer how the linked list is split in place.

rsKayiira
Автор

I think you should have mentioned that it is a good practice to keep the linkedlist in its original form before returning the answer.

guyipod
Автор

Thank you very much for the clear explanation :)~

benyaminyakobi
Автор

Hi,

Since this question is super important and it is frequently asked, can we discuss a better solution than this?
Although it is accepted by LeetCode, the interviewer would say that my Linked List got broken, I could offer to re-reverse the second half and put the list back together.
But the interviewer would further note that the proposed solution is not suitable for a concurrent environment, where multiple threads or processes may concurrently access the same data.
And for sure, one potential disadvantage of modifying a Linked List is that it can temporarily disrupt the structure of the list, which can cause issues if other threads or processes try to access the list at the same time.
One answer to avoid such issues can be to use locks or other synchronization mechanisms to ensure that only one thread or process can access the list while it is being modified.
But the interviewer will confirm that this can add additional overhead and complexity to the code.
SUMMARY: a nightmare :D
Can you discuss O(1) space complexity other than modify the list in place?

I would much appreciate it if you get back to me.
Best,
Nataša

natasaivic
Автор

Hey, thanks a ton for doing these! I am coming from your answer on quora.

momentime