Загрузка...

Linked List Cycles: The One Formula Everyone Gets Wrong

Why does resetting one pointer to head and moving both at speed=1 always find the cycle start?
Most people memorize the trick. Today, you'll actually understand WHY it works.

If you're prepping for placements
this is LC 142 | GFG: Find the first node of loop in linked list.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🧩 WHAT YOU'LL LEARN
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ Detect if cycle exists (LC 141 recap — 1 min)
✅ Why slow and fast meet inside the cycle
✅ The math behind why head + meeting point → gives the START
✅ Full dry run on an example
✅ Clean C++ code walkthrough
✅ Time: O(N) | Space: O(1) — why it beats HashMap
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📌 LINKS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔗 LeetCode 142 → https://leetcode.com/problems/linked-list-cycle-ii/
🔗 Previous video (LC 141 – Detect Cycle) → https://youtu.be/qaoCTTtDW6c?si=lvcZtREYpizgXkCh
🔗 Instagram for 50-sec visual reels → https://instagram.com/theshinelabs

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
👋 ABOUT THIS CHANNEL
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Shine Labs is for 3rd & 4th year CS students who've solved 200+ problems
but still blank out when an interviewer asks "explain your approach."

We break down DSA patterns so you don't just solve — you think, explain, and get hired.

Видео Linked List Cycles: The One Formula Everyone Gets Wrong канала ShineLabs
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять