Linked List Cycle (LeetCode 141) | Full solution with demo | Floyd Warshall | Study Algorithms

preview_player
Показать описание
A really interesting problem where you are required to determine if there is a cycle in a linked list. A loop/cycle is formed if one of the pointers in the linked list points to an internal node in the same list. There are a lot of ways to solve this problem and hence it is very important for interviews. The video explores how you can use a hash table to keep a track of unique nodes and then it demonstrates how the hare tortoise algorithm actually works. A dry-run of code in JAVA is also included.

Chapters:
00:00 - Intro
01:29 - Problem statement and description
03:46 - Brute Force approach to detect a cycle
07:55 - Idea behind an efficient approach (Rabbit/Tortoise method)
10:40 - Efficient solution (Floyd Warshall algorithm)
12:42 - Dry-run to detect cycle
15:02 - Final Thoughts

📚 Links to topics I talk about in the video:

📖 Reference Books:

🎥 My Recording Gear:

💻 Get Social 💻

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

You are just greek god of teaching complex stuff in the simplest way possible!! God bless for your efforts.

sheldoncooper
Автор

What an explaination. Calm, cool, smiling, no use of complex words, it was like listening to a story. ❤ Subscribed!!!

debottamyoutube
Автор

I must say you speak very politely and your explanation is LIT 🔥 🔥 🔥 🔥.
I personally find your videos better NeetCode.
Hope your channel grows!!!💜

JammUtkarsh
Автор

I referred to a few other videos about this leetcode problem and finally found this one helpful.

vinodsurineeda
Автор

Wow, I can't imagine you explained this problem so well. Thanks a lot bhaiya❤😊

GrowWithHare
Автор

Your entire linked list playlist is amazing Nikhil!

matthewzarate
Автор

Very good explanation. in while condition, slow != null is not required because slow pointer is always behind fast and if there is a null, it's detected by fast pointer and we break out of loop

pranavm
Автор

thank u so much .i have been searching only for ur solution for evry prblm and go to other videos only if ur video is not present.ur videos and visuals bring more interest for me to solve problems

kayathrivenkatesan
Автор

Thanks Nikhil, for explaining the approach so nicely

akashchakrabortty
Автор

Nikhil Bhai, Thankyou so much
i got clarity on LL through your videos only...Very clear explanation
you are doing great job Brother
Proud of you.

divyaawasthi
Автор

What an awesome explanation.Sir could you please come up with the continuation of the video on how to find the node at which the cycle occurs?, will be of great help

hamdasalam
Автор

Really I love your way of explanation...Also it made me easy to understand..

arupbasak_storytelling
Автор

your channel is underated, your videos are amazing bro, awesome explanation please keep posting new video's in english

chakravarthybatna
Автор

Very nice and easy to understand explanation! Subscribed! 😄

hunorvadasz-perhat
Автор

You hoped you simplified the solution. And yes you are Sire! you indeed simplified it.
I hope i could give you a cookie.

alisheheryar
Автор

Ur vidoes are really helpful. Pls cover more problems

parthmodi
Автор

Hi Thanks fo the video. Can you explain why while loop has 3 conditions? if fast pointer reaches null, its already proven that it doesnt have loo. also fast pointer will always reach null first, so why check for slow pointer is null or not? and why check fast pointer.next is null?

preetijavali
Автор

can you pls explain what the purpose of fastPtr.next != null condition in the while loop? i understand that if slowPtr or fastPtr is null then it is not a cycle but why the third condition?

johncho
Автор

Hi Nikhil, thanks for the amazing video, just one query do we really need the condition slowPtr!=null on the while loop ?

jayaveeran
Автор

very good explanation & easy to understand . Jus wanted to ask which application you use for writing in ipad like (goodnote, notability)

TechTribers