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
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
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
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?
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?
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.
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
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 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.
You are just greek god of teaching complex stuff in the simplest way possible!! God bless for your efforts.
haha...will try my best to keep bringing such content
What an explaination. Calm, cool, smiling, no use of complex words, it was like listening to a story. ❤ Subscribed!!!
I must say you speak very politely and your explanation is LIT 🔥 🔥 🔥 🔥.
I personally find your videos better NeetCode.
Hope your channel grows!!!💜
As long as you understand things, it is all that matters. 🙂
Wow, I can't imagine you explained this problem so well. Thanks a lot bhaiya❤😊
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
Your entire linked list playlist is amazing Nikhil!
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
Thanks Nikhil, for explaining the approach so nicely
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.
thanks so much
Very nice and easy to understand explanation! Subscribed! 😄
thank you for subscribing.. :)
Really I love your way of explanation...Also it made me easy to understand..
Happy to help
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
youre an amazing tutor nikhil! Cheers
thanks for the comment
Extraordinary 🎉🎉
Great explanation 🔥
your channel is underated, your videos are amazing bro , awesome explanation please keep posting new video's in english
I will try my best
Great explanation! Thank you!
Superb explanation
Ur vidoes are really helpful. Pls cover more problems
a new video every week.
Great explanation :)
superb explanation boss
Keep watching
Hatsofff sirr🙌🫡🫡
plz make more videos, its so helpful
Very nice explanation Brother
such a
simple explaination
Thank you AGAIN!!
You hoped you simplified the solution. And yes you are Sire! you indeed simplified it.
I hope i could give you a cookie.
👍🏻
Beautiful baba!
Thanks a ton sir !! subbed🙂
Thanks for the sub!
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?
you are right...we can get rid of slowPtr check in the while loop.
@@nikoo28 Thank you.
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?
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
Hi Nikhil, thanks for the amazing video, just one query do we really need the condition slowPtr!=null on the while loop ?
very good explanation & easy to understand . Jus wanted to ask which application you use for writing in ipad like (goodnote ,notability)
GootNotes 6
what application do you use to write in tab?
That would be Goodnotes 6.
@@nikoo28 Thank you !
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?
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.
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
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
You can just copy the test case inside the main method and it will work
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😅
that works too, but then you are modifying the actual list. confirm with your interviewer if you are allowed to make changes.
Yeah
I can't find the solution for this thing
"Where to find the cycle first"😢
this: th-cam.com/video/95ZfuoSAUPI/w-d-xo.html
How to display value instead of true and false
Once you identify the node you stop at, you can store it's value somewhere and then return it.
It would be good If you have made this video in hindi as there are not much viewers who don't understand hindi.
i will try to add subtitles in other languages
Sorry bro!
Your solution exceeded the time limit of leetcode constraints.
This approach is not accepted in Leetcode.
That can’t be possible, did you check the code in the github link available in the description? It passes on LeetCode
@@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.
@@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.
thank you so much you are the best!!!!!