L14. Detect a loop or cycle in LinkedList | With proof and Intuition

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.ย. 2024
  • Problem Link: tinyurl.com/3r...
    Entire LL Sheet: takeuforward.o...
    Check our A2Z DSA Course: takeuforward.o...
    Please do give us a like, and subscribe to us if you are new to our channel.
    Do follow us on our socials: linktr.ee/take...

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

  • @md.ualiurrahmanrahat2400
    @md.ualiurrahmanrahat2400 7 หลายเดือนก่อน +77

    No one even in paid courses also give the intuition behind the algorithms like you did Sir. You could have earned millions by paid courses but instead you chose to contribute for the greater well of the society. Hats off!

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

      bro , i am with you in all of your debate , still he is earning heavily due to yt , maybe not particularly this video with 53k views at this point but he has videos with million views too

    • @md.ualiurrahmanrahat2400
      @md.ualiurrahmanrahat2400 หลายเดือนก่อน

      @@sakshammisra189 Yes. But he is not only earning money. He is earning prayers and blessings of millions of students like us. He is helping even foreign countries students as you won't see much videos from them. Indian TH-camrs took teaching to the next level through TH-cam.Thousands of us will get inspired to contribute like him when we become successful and have the opportunity. That's how he is shaping our minds.

    • @priyanshugupta7840
      @priyanshugupta7840 23 วันที่ผ่านมา

      @@sakshammisra189 Atleast, he is redeeming what he earns with his efforts and generosity

  • @adarshjhanitkurukshetra
    @adarshjhanitkurukshetra 8 หลายเดือนก่อน +67

    Whole NIT and IIT follows you ♥, hats off

    • @AdityaGupta-cx1ej
      @AdityaGupta-cx1ej 7 หลายเดือนก่อน +9

      Bro I am in IIIT-Kottayam we also follow not just IIT and Nit🙂

    • @frouMagician
      @frouMagician 2 หลายเดือนก่อน +7

      @@AdityaGupta-cx1ej well, he did not say "only" NITs and IITs follow him, did he ?

  • @kamalakannanng4206
    @kamalakannanng4206 5 หลายเดือนก่อน +15

    The whole video is 10/10 but the intuition part is 1000/10. Just Striver things 🔥

  • @bishalkundu7592
    @bishalkundu7592 9 หลายเดือนก่อน +34

    Knew this algorithm but came here to learn the proof ❤ And guess what Striver Bhaiyaa never disappoints ❤

  • @divyatejaswinivengada6368
    @divyatejaswinivengada6368 6 หลายเดือนก่อน +5

    Hands down the best explanation I have seen in so many year's , I am forever grateful for such beautiful intuition and explanation

  • @_CodeLifeChronicles_
    @_CodeLifeChronicles_ 3 หลายเดือนก่อน +2

    the best dsa course. i can code myself after the intuition.explanaton is crystal clear

  • @user-ql5pe3xc3p
    @user-ql5pe3xc3p 4 หลายเดือนก่อน +5

    Bro , i write my own bro by seeing your explanation ❤️
    You are my God bro 🫂

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

    The intuition part!🤌💯

  • @aman_deep21
    @aman_deep21 24 วันที่ผ่านมา +1

    Great explanation of the intuition ❤

  • @arzooqureshi8821
    @arzooqureshi8821 9 หลายเดือนก่อน +5

    I am so glad i found this channel.The Best!

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

    Understood very well. I just love the way you teach. Love you Striver Bro ❤ One day or other I will meet you in the Google office or somewhere else and I will thank you personally by hugging you tight Bhai ❤

  • @anuplohar23
    @anuplohar23 6 หลายเดือนก่อน +4

    18:25 That's the reason why I preferred Striver's DSA playlist

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

    Awesome video! I was doubting you'd actually explain the intuition in an intuitive way but you did it, thank you!!

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

    Hi,
    Remember one thing slow and fast pointer will always meet if the ratio b/w speed of slow and fast pointer is greater than 1. There ratio can be in decimal also , But if you want them to meet fast in the loop then optimal speed will be slow = 1 and fast = 2.
    But if the two pointers move like slow = 3 and fast = 5 then they also meet. It will take multiple cyle but they will eventually meet.

    • @priyanshugupta7840
      @priyanshugupta7840 23 วันที่ผ่านมา +1

      Can you please explain how that works?

  • @deepakbhatt03
    @deepakbhatt03 8 หลายเดือนก่อน +3

    This is real teaching!

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

    🙌 Loved the way you explained the problem solution and intuition .
    Thank you very much .

  • @AbhijitSahoo-oc2lz
    @AbhijitSahoo-oc2lz 8 หลายเดือนก่อน +2

    Many many Thanks for your effort Bhaiyaa ❤ you are in those teacher's of my life which i can never forger in my life❤💯

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

    If you still confused in H T approach then
    Imagine, the distance between Hare and Tortoise is 5m.
    So according to logic we move Tortoise by 1, the distance will be 5m and Hare by 2.
    So them the overall distance will be 6-2 =4m
    Our distance got reduced by 4m
    And if you keep continuing the approach eventually our distance will be zero
    And the same approach might work in 3. Bit it's depend on luck
    Like 5+1 = 6. Then 6-3 = 3m
    Again, 3+1= 4. Them 4-3 = 1m
    Again, 1-1 = 2. Them 2-3 = -1 m
    Overlapping.....

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

    What a clarity !!! God level explanation at end

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

    Understood, thanks striver for this amazing video.

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

    big hats off for the intuition part!!!🙌❤❤

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

    Wonderful explanation striver!!! You are really doing an incredible job!!

  • @ishantsharma8139
    @ishantsharma8139 15 วันที่ผ่านมา

    You are best teacher on TH-cam ❤

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

    Thankyou Sir for teaching us real problem solving.

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

    the best explanation on the internet.

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

    Your at a whole new level

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

    Striver bhaiya linked list ki sbhi videos jldi se upload kr do , next month interview bhi h😇

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

      All the best brother 🎉

    • @shreyxnsh.14
      @shreyxnsh.14 7 หลายเดือนก่อน +1

      how did it go?

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

      @@shreyxnsh.14 It was ok

    • @anindyapaul9735
      @anindyapaul9735 29 วันที่ผ่านมา

      For which company?​@@rahulmandal4007

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

    thanks for telling us the why 😁

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

    Best DSA in YT

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

    great way to explain why fast and slow ptointers will collide definitely..🙅

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

    Great Striver🤩🤩

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

    Awesome Explanation!

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

    Man you're a GENIUS !!!

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

    Awesome content Sir......

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

    very well explained
    Dek raha ha Binod Kitna easy hota ha DSA.....

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

    A great explanation bro....... ❤

  • @user-ik3qu5uy5e
    @user-ik3qu5uy5e 6 หลายเดือนก่อน

    you are great sir ! loads of love

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

    17:44 correction if we move slow by 1 and fast by 2,3,4,5 etc we still collide and get the answer i ve prove it if you want you can increment fast by >=2 by having the appropriate while check

    • @shreyxnsh.14
      @shreyxnsh.14 7 หลายเดือนก่อน

      so that means what he said is wrong?

    • @shreyxnsh.14
      @shreyxnsh.14 7 หลายเดือนก่อน

      3,4,5 wont work if the list has just 2 elements

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

      @@shreyxnsh.14 kind of yes or we can say that he hasnt explored about that…

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

    Striver only had one issue that could be heard from a few that his lectures are not beginer friendly.
    Now that's all the past , it is settled. This is BEST content to exist for all the STRIVERS out there to learn dsa period.! No matter how much dsa u have done earlier even if u r a beginer the A2Z sheet is hands down the best+

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

    You are the best!!

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

    Understood 😊

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

    Understood, thank you.

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

    wish i could give you 1000 likes at once. Great explaination.

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

    GOD OF DSA->STRIVER

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

    Thx sir ,can u pls bring string playlist sir pls pls pls😅😅 i m excited for it...

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

    While putting the condition fast!=NULL should come before fast->next != NULL,if you do vice versa then it will show pointer error

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

    while(fast !=null){
    fast = fast->next;
    fast = fast -> next;
    slow = slow ->next;
    If(fast->next == slow) return true;
    }
    return false;

    • @VIJAYSHARMA-dh6vo
      @VIJAYSHARMA-dh6vo 8 หลายเดือนก่อน

      instead of using fast->next 2 times you can simply write fast->next->next :)

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

      @@VIJAYSHARMA-dh6vo I know :). But my intention was to make it more obvious that fast is taking two steps when slow just takes one. Also I wanted to avoid that extra ugly check in while, ie, && fast->next->next != null (just a personal preference.)

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

    More efficient time and space complexity solution
    bool hasCycle(ListNode *head)
    {
    if(head==NULL || head->next==NULL)return false;
    ListNode*temp=head;
    while(temp)
    {
    if(temp->val==1e8)return true;
    temp->val=1e8;
    temp=temp->next;
    }
    return false;
    }

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

    thank you

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

    Thanks striver

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

    Understood

  • @shubhamchaudhary8688
    @shubhamchaudhary8688 7 วันที่ผ่านมา

    Intution - ground mein do ladke bhaag rahe ek dusre se tez hai...aisa koi na koi point to aega hi na jab tez wala ladka dhere wale ko pakad lega.

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

    Thank you so much!!

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

    Understood✅🔥🔥

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

    Or we can also say, if fast->next == slow return true; to optimize by one step.

  • @user-tk2vg5jt3l
    @user-tk2vg5jt3l 6 หลายเดือนก่อน

    Thank you bhaiya

  • @user-or5oz1pk2x
    @user-or5oz1pk2x 5 หลายเดือนก่อน

    Thanks A Lot

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

    bool hasCycle(ListNode *head) {
    if(head == NULL) return false;
    ListNode* temp = head;
    int n = 10000; //given contraint
    for(int i=0; inext == NULL){
    return false;
    }
    temp = temp->next;
    }
    return true;
    }
    big brain move

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

    understood

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

    Understood!!

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

    13:40 will know the intuition behind why slow and fast pointer will meet

  • @NARUTOUZUMAKI-bk4nx
    @NARUTOUZUMAKI-bk4nx 7 หลายเดือนก่อน

    Understooood

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

    underestood

  • @Abhishekthakur-mg4el
    @Abhishekthakur-mg4el 9 หลายเดือนก่อน

    thanks bhai❤

  • @user-ed8bc2hg5o
    @user-ed8bc2hg5o หลายเดือนก่อน

    understand

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

    thanks bro

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

    Thanks

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

    understood!

  • @anikesh001-qwe
    @anikesh001-qwe หลายเดือนก่อน

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

    Thank you !🌄

  • @4everachyut
    @4everachyut 3 หลายเดือนก่อน

    Is it necessary to increase the fast pointer only by 2? What if we increased it by 3 or 4? Will it still meet the slow pointer?

    • @anindyapaul9735
      @anindyapaul9735 29 วันที่ผ่านมา

      See the video completely. U will get to know

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

    🐐

  • @HarshMishra-hp2lt
    @HarshMishra-hp2lt 3 หลายเดือนก่อน

    Can we also use unordered_set instead of map?

  • @saranshbhole8500
    @saranshbhole8500 21 วันที่ผ่านมา

    Wrong Answer
    15 / 29 testcases passed
    Editorial
    Inputhead =[1,2]
    pos = -1
    Use Testcase
    Output=true
    Expected=false
    the above test case fails to do so what about this condition?

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

    ListNode* temp = head;
    int i = 0;
    while(temp){
    if(temp && temp->val == INT_MAX) return true;
    temp->val = INT_MAX;
    temp = temp->next;
    }
    return false;
    Can this be a solution??? can i tell this to the interviwer ?

  • @user-gw5kf6ih9s
    @user-gw5kf6ih9s 5 หลายเดือนก่อน

    relative motion yaad agaya

  • @user-jb2xz5ge5h
    @user-jb2xz5ge5h 17 วันที่ผ่านมา

    what if it has same elements ?

  • @user-sl9xm3cm3p
    @user-sl9xm3cm3p 3 หลายเดือนก่อน

    Why not use a set instead of map?

  • @user-ot1rd8hd3d
    @user-ot1rd8hd3d 7 หลายเดือนก่อน

    undersood

  • @SunnyKumar-dw9ze
    @SunnyKumar-dw9ze 9 หลายเดือนก่อน

    👍

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

    In your old website you given those links but now what you have given in your link is not good videos

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

    US

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

    what if the length of LL is 1 or 2?? will this code throw a error??

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

    Time Complexity of this ?

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

    When we will move slow by 1 and fast by 3..then also they will collide....Yrr I don't understand why we are moving slow by 1 and fast by 2..pls anyone can help???

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

      If we follow, slow by by 1 and fast by 3 the resultant reduction between them will be 2 , and consider if initial b/w tem is 7 the follow will like this 7 - 5 - 3 - 1 - (-1)... No collision of them

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

      Thanks @@nishantgupta5015

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

    Your explanation is op
    💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥
    💥
    ❤‍🩹

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

    us

  • @user-kn4zc2gt3r
    @user-kn4zc2gt3r 2 หลายเดือนก่อน

    please use some hindi words please so that north indian student understand easily

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

    Understood

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

    Understood
    😇

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

    Understood!

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

    US

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

    Understood

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

    Understood

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

    Understood

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

    Understood

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

    Understood

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

    Understood