Тёмный

Linked List Cycle 2 (LeetCode 142) | Full solution with mathematical proof | Study Algorithms 

Nikhil Lohia
Подписаться 39 тыс.
Просмотров 7 тыс.
50% 1

Given a single linked list that contains a loop, find the node where the cycle starts. A very famous problem and an extension of detecting the loop. Using a slow pointer and fast pointer, can help to determine the meeting point. This video gives a mathematical proof on how the pointers meet at the start of loop. All along with diagrams and a dry-run of code in JAVA.
Chapters:
00:00 - Intro
01:11 - Problem statement and description
02:11 - Brute Force approach to find the cycle start point
05:16 - Efficient solution to find the cycle start point
08:27 - Mathematical proof of Floyd-Warshall algorithm
14:52 - Dry-run of code
16:55 - Final Thoughts
Actual problem on LeetCode: leetcode.com/problems/linked-...
📚 Links to topics I talk about in the video:
Detect Cycle in Linked List: • Linked List Cycle (Lee...
Linked List Introduction: • Linked List Data Struc...
Linked List Traversals: • Traversing a Linked Li...
Brute Force Method: • Brute Force algorithms...
Time Complexity: • Big O Notation Simplif...
Playlist on Linked Lists: • Linked Lists
📘 A text based explanation is available at: studyalgorithms.com
Code on Github: github.com/nikoo28/java-solut...
Test-cases on Github: github.com/nikoo28/java-solut...
📖 Reference Books:
Starting Learn to Code: amzn.to/36pU0JO
Favorite book to understand algorithms: amzn.to/39w3YLS
Favorite book for data structures: amzn.to/3oAVBTk
Get started for interview preparation: amzn.to/39ysbkJ
🔗 To see more videos like this, you can show your support on: www.buymeacoffee.com/studyalg...
🎥 My Recording Gear:
Recording Light: amzn.to/3pAqh8O
Microphone: amzn.to/2MCX7qU
Recording Camera: amzn.to/3alg9Ky
Tablet to sketch and draw: amzn.to/3pM6Bi4
Surface Pen: amzn.to/3pv6tTs
Laptop to edit videos: amzn.to/2LYpMqn
💻 Get Social 💻
Follow on Facebook at: / studyalgos
Follow on Twitter at: / studyalgorithms
Follow on Tumblr at: / studyalgos
Subscribe to RSS feeds: studyalgorithms.com/feed/
Join fan mail: eepurl.com/g9Dadv
#leetcode #programming #linkedlists

Опубликовано:

 

4 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 45   
@jayachandranpm3981
@jayachandranpm3981 2 года назад
A teacher deserves the highest appreciation in the world.
@curiousnerd2253
@curiousnerd2253 5 месяцев назад
Oh my god! Why is your solution not the most viewed solution?!. Just amazing! Thank you so much!
@nikoo28
@nikoo28 4 месяца назад
You're welcome!
@shraddhajain8935
@shraddhajain8935 2 года назад
Thanks a lot for such a detailed, simplified, and perfect explanation. I wish this will reach to max students.
@nikoo28
@nikoo28 2 года назад
Thanks for all the support
@astonvaz2247
@astonvaz2247 3 месяца назад
Very well explained. Had seen the solution about moving fast pointer to head but couldn't agree, but now after watching the visual explanation, I'm very clear. Thanks again buddy. 👍
@azharsofi2854
@azharsofi2854 Год назад
Your art of teaching is amazing
@darkexodus6404
@darkexodus6404 Год назад
Brilliant explanation!!
@umtropaqualquer
@umtropaqualquer 2 месяца назад
Thanks for the explanation! was able to understand the logic behind it!
@jaydeepvasoya6243
@jaydeepvasoya6243 3 месяца назад
mathematical explanation is super...!! thanks a lot..!
@hieua3137
@hieua3137 7 часов назад
Great Explanation !!!!
@RwSkipper007
@RwSkipper007 Месяц назад
what a question and what an explaination!!!
@AadeshKulkarni
@AadeshKulkarni 4 месяца назад
This mathematical proof is so beautifully explained! I'm loving it baba!
@nikoo28
@nikoo28 3 месяца назад
Happy to hear that!
@susmitapatil4847
@susmitapatil4847 5 месяцев назад
Very good teacher he is. He explains every concept very well. keep doing good work. Thanks for providing such content for free
@nikoo28
@nikoo28 4 месяца назад
Thanks a ton
@user-fc6xb6ww8r
@user-fc6xb6ww8r Год назад
Great content!
@Walid-Sahab
@Walid-Sahab 9 месяцев назад
what an explanation ❤
@yixiangzhang2834
@yixiangzhang2834 Год назад
very well explained.
@user-dj3hs4ff5v
@user-dj3hs4ff5v 10 месяцев назад
perfect content!!!
@adityaa2303
@adityaa2303 9 месяцев назад
good explanation sir
@mubeenakabeer6850
@mubeenakabeer6850 26 дней назад
good explanation
@techtuber1344
@techtuber1344 4 месяца назад
best explanation buddy , you got my sub:)
@nikoo28
@nikoo28 4 месяца назад
Thanks for the sub! 😄
@oLittleFive
@oLittleFive Месяц назад
Thanks for the detailed explanation! I have a question: Why is (n2 - 2n1) always a positive integer? Can it be negative?
@infinite639
@infinite639 Год назад
Very Nice bro
@user-ur7pe9qp4i
@user-ur7pe9qp4i 6 месяцев назад
Hitting that subbscribe button as hard as I can.
@smitdumore1064
@smitdumore1064 9 месяцев назад
great explanation
@nikoo28
@nikoo28 8 месяцев назад
glad you liked it
@tias9719
@tias9719 2 года назад
Simplified explaination 👍🏻 Can you please suggest any book to study detailed data structures?
@nikoo28
@nikoo28 2 года назад
I have links to some books in the video description. Check them out 🙂
@tias9719
@tias9719 2 года назад
@@nikoo28 noted. Thanks
@AzharKhan-e9m
@AzharKhan-e9m 3 дня назад
new subscriber
@manjarijha7755
@manjarijha7755 2 года назад
Thanks
@kashishjaiswal9303
@kashishjaiswal9303 Год назад
tysmm...i wasnt able to understand any solution for this on yt until i saw your vid sir!!😭😭
@Salah-YT
@Salah-YT 8 месяцев назад
👍😍😎...
@gauravsharma5584
@gauravsharma5584 8 месяцев назад
isnt floyd warshall graph algorithm ??
@darkexodus6404
@darkexodus6404 Год назад
@nikoo28 At 14:22 Why only slow pointer? Why not fast pointer?
@rakheesharma7994
@rakheesharma7994 9 месяцев назад
Because slow pointer is advancing one node at a time and fast is jumping two nodes. Hence we use the movement of slow pointer to get the length.
@paparika567
@paparika567 3 месяца назад
no bro you can take slow pointer as well
@AzharKhan-e9m
@AzharKhan-e9m 3 дня назад
you can take slow as well but make sure that fast also go only one step like fast=fast.next just as head=head.next beacoz distance is same by mathematical proofs so take as u need
@srikanthchebrolu1091
@srikanthchebrolu1091 3 месяца назад
💌
@Walid-Sahab
@Walid-Sahab 9 месяцев назад
Love from Pakistan ❤
@user-ym8wk9yv3y
@user-ym8wk9yv3y 9 месяцев назад
sir second approach is not fine when the loop starts ate head
@nikoo28
@nikoo28 8 месяцев назад
can you please elaborate?
Далее
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36