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

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 พ.ย. 2024

ความคิดเห็น • 75

  • @sheldoncooper7990
    @sheldoncooper7990 ปีที่แล้ว +16

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

    • @nikoo28
      @nikoo28  ปีที่แล้ว

      haha...will try my best to keep bringing such content

  • @debottamyoutube
    @debottamyoutube 9 หลายเดือนก่อน +3

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

  • @JammUtkarsh
    @JammUtkarsh ปีที่แล้ว +11

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

    • @nikoo28
      @nikoo28  ปีที่แล้ว +2

      As long as you understand things, it is all that matters. 🙂

  • @GrowWithHare
    @GrowWithHare 5 หลายเดือนก่อน +1

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

  • @pranavm9301
    @pranavm9301 10 หลายเดือนก่อน +2

    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

  • @matthewzarate8851
    @matthewzarate8851 6 หลายเดือนก่อน

    Your entire linked list playlist is amazing Nikhil!

  • @kayathrivenkatesan7712
    @kayathrivenkatesan7712 7 หลายเดือนก่อน

    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

  • @akashchakrabortty2431
    @akashchakrabortty2431 ปีที่แล้ว

    Thanks Nikhil, for explaining the approach so nicely

  • @divyaawasthi8286
    @divyaawasthi8286 ปีที่แล้ว

    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.

    • @nikoo28
      @nikoo28  ปีที่แล้ว

      thanks so much

  • @hunorvadasz-perhat6001
    @hunorvadasz-perhat6001 ปีที่แล้ว

    Very nice and easy to understand explanation! Subscribed! 😄

    • @nikoo28
      @nikoo28  ปีที่แล้ว

      thank you for subscribing.. :)

  • @arupbasak919
    @arupbasak919 ปีที่แล้ว

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

    • @nikoo28
      @nikoo28  ปีที่แล้ว

      Happy to help

  • @hamdasalam4373
    @hamdasalam4373 5 หลายเดือนก่อน

    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

  • @TuringTested01
    @TuringTested01 ปีที่แล้ว

    youre an amazing tutor nikhil! Cheers

    • @nikoo28
      @nikoo28  ปีที่แล้ว

      thanks for the comment

  • @abhineveash
    @abhineveash หลายเดือนก่อน

    Extraordinary 🎉🎉

  • @Dadu-g4r
    @Dadu-g4r ปีที่แล้ว +1

    Great explanation 🔥

  • @chakravarthybatna1589
    @chakravarthybatna1589 ปีที่แล้ว

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

    • @nikoo28
      @nikoo28  ปีที่แล้ว

      I will try my best

  • @safar19899
    @safar19899 ปีที่แล้ว

    Great explanation! Thank you!

  • @JH-wy2pc
    @JH-wy2pc ปีที่แล้ว

    Superb explanation

  • @parthmodi2028
    @parthmodi2028 9 หลายเดือนก่อน

    Ur vidoes are really helpful. Pls cover more problems

    • @nikoo28
      @nikoo28  8 หลายเดือนก่อน

      a new video every week.

  • @mayankbadika3101
    @mayankbadika3101 9 หลายเดือนก่อน

    Great explanation :)

  • @SATYAMTIWARI-ps3wb
    @SATYAMTIWARI-ps3wb ปีที่แล้ว

    superb explanation boss

    • @nikoo28
      @nikoo28  ปีที่แล้ว

      Keep watching

  • @mahatrt
    @mahatrt 3 หลายเดือนก่อน +1

    Hatsofff sirr🙌🫡🫡

  • @IshaZaka
    @IshaZaka 2 หลายเดือนก่อน

    plz make more videos, its so helpful

  • @ashokrajan9401
    @ashokrajan9401 2 ปีที่แล้ว

    Very nice explanation Brother

  • @Thirushal007
    @Thirushal007 9 หลายเดือนก่อน

    such a
    simple explaination

  • @CodingSquirrel777
    @CodingSquirrel777 ปีที่แล้ว

    Thank you AGAIN!!

  • @alisheheryar1770
    @alisheheryar1770 8 หลายเดือนก่อน

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

  • @vaishnavidubey7784
    @vaishnavidubey7784 หลายเดือนก่อน +1

    👍🏻

  • @AadeshKulkarni
    @AadeshKulkarni 9 หลายเดือนก่อน

    Beautiful baba!

  • @Sai-fn4lq
    @Sai-fn4lq ปีที่แล้ว

    Thanks a ton sir !! subbed🙂

    • @nikoo28
      @nikoo28  ปีที่แล้ว

      Thanks for the sub!

  • @preetijavali6595
    @preetijavali6595 9 หลายเดือนก่อน +1

    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?

    • @nikoo28
      @nikoo28  9 หลายเดือนก่อน

      you are right...we can get rid of slowPtr check in the while loop.

    • @preetijavali6595
      @preetijavali6595 9 หลายเดือนก่อน

      @@nikoo28 Thank you.

  • @johncho9160
    @johncho9160 10 หลายเดือนก่อน +1

    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?

    • @nikoo28
      @nikoo28  9 หลายเดือนก่อน

      we want to make sure that we don't hit null pointer. It is not necessary that the linked list has a cycle for sure

  • @jayaveeran1
    @jayaveeran1 5 หลายเดือนก่อน

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

  • @TechTribers
    @TechTribers 5 หลายเดือนก่อน

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

    • @nikoo28
      @nikoo28  5 หลายเดือนก่อน

      GootNotes 6

  • @vaibhavkgote
    @vaibhavkgote ปีที่แล้ว +1

    what application do you use to write in tab?

    • @nikoo28
      @nikoo28  ปีที่แล้ว

      That would be Goodnotes 6.

    • @vaibhavkgote
      @vaibhavkgote ปีที่แล้ว

      @@nikoo28 Thank you !

  • @priyanshgarg1292
    @priyanshgarg1292 ปีที่แล้ว +1

    WHY NOT WE ARE moving hare with 3x or 4x or 5x etc... speed then also it will come in loop why only 2x speed?

    • @nikoo28
      @nikoo28  ปีที่แล้ว +3

      While you could potentially use a higher speed like 3x, 4x, or 5x, using a speed of 2x ensures that the hare and tortoise pointers will eventually meet if there is a cycle. Using a higher speed than 2x might not guarantee this outcome.
      Let's explore the reasoning behind using a 2x speed for the fast pointer:
      - Balanced Progress: Moving the fast pointer at 2x the speed of the slow pointer creates a balanced progression. This ensures that the fast pointer catches up to the slow pointer at a steady rate.
      - Guaranteed Intersection: In a linked list with a cycle, the fast pointer will eventually enter the cycle. Since the cycle has a finite length, the fast pointer will "lap" the slow pointer (that's moving at a 1x speed) before they meet again.
      - Avoiding Overlooking Cycles: If you were to use a higher speed for the fast pointer, like 3x or 4x, you might inadvertently overshoot or skip over some cycles. This is because the fast pointer might move through multiple complete cycles while the slow pointer is still traversing through a single cycle.
      - Minimal Tracking: Using a 2x speed minimizes the number of steps required to find a cycle. While increasing the speed might lead to faster movement, it doesn't guarantee a more efficient cycle detection process.

  • @shraddhajain8935
    @shraddhajain8935 2 ปีที่แล้ว

    Hey! can you explain the while condition a bit more? For me it is failing for a test case like '[-21,10,17,8,4,26,5,35,33,-7,-16,27,-12,6,29,-12,5,9,20,14,14,2,13,-24,21,23,-21,5]
    -1'
    when it comes to a point where 'fast.next.next' is None. It is working when we are adding a null check for fast.next.next as well

  • @infinite639
    @infinite639 2 ปีที่แล้ว +1

    I can run the code on Leetcode but
    But i want to run it on my local IDE as a normal input output program
    You have only written test cases

    • @nikoo28
      @nikoo28  2 ปีที่แล้ว +3

      You can just copy the test case inside the main method and it will work

  • @kidoo1567
    @kidoo1567 ปีที่แล้ว

    Is this approach correct.. change the value of every node we are traversing as max integer. And check if we reach the node max integer again while traversing print true😅

    • @nikoo28
      @nikoo28  ปีที่แล้ว

      that works too, but then you are modifying the actual list. confirm with your interviewer if you are allowed to make changes.

    • @kidoo1567
      @kidoo1567 ปีที่แล้ว

      Yeah

  • @sharabugnanesh3098
    @sharabugnanesh3098 ปีที่แล้ว

    I can't find the solution for this thing
    "Where to find the cycle first"😢

    • @nikoo28
      @nikoo28  ปีที่แล้ว

      this: th-cam.com/video/95ZfuoSAUPI/w-d-xo.html

  • @kalyanamvenumadhav2245
    @kalyanamvenumadhav2245 ปีที่แล้ว

    How to display value instead of true and false

    • @nikoo28
      @nikoo28  ปีที่แล้ว

      Once you identify the node you stop at, you can store it's value somewhere and then return it.

  • @shivangchauhan820
    @shivangchauhan820 ปีที่แล้ว

    It would be good If you have made this video in hindi as there are not much viewers who don't understand hindi.

    • @nikoo28
      @nikoo28  ปีที่แล้ว

      i will try to add subtitles in other languages

  • @abuyousuf7281
    @abuyousuf7281 11 หลายเดือนก่อน

    Sorry bro!
    Your solution exceeded the time limit of leetcode constraints.
    This approach is not accepted in Leetcode.

    • @nikoo28
      @nikoo28  11 หลายเดือนก่อน

      That can’t be possible, did you check the code in the github link available in the description? It passes on LeetCode

    • @abuyousuf7281
      @abuyousuf7281 11 หลายเดือนก่อน

      @@nikoo28 sorry brother about my last comment.
      Yes this approach is good enough but I tried your same concept but that showed time limit exceeded. I want to let you know that I used Java.
      But after that I had seen another video which is same approach but differently. Like: ListNode slow = head;
      ListNode fast = head.next;a
      while(){
      ....
      slow = slow.next;
      fast = fast.next.next;
      }
      Return true;
      And Buddy that passed the time limit constraint.

    • @abuyousuf7281
      @abuyousuf7281 11 หลายเดือนก่อน

      @@nikoo28 Don't get me wrong sir,
      You’ve done an amazing job.
      Just wanted to let you know I've failed to pass my time limit.

  • @rodba1393
    @rodba1393 9 หลายเดือนก่อน

    thank you so much you are the best!!!!!