i have been watching your dsa series since almost 1 month. this intuition shocked me... literally.. no youtuber or tutor teaches the way you teach. i really appreciate the way you teaches ... hats off sir.
Another way to put the intuition can be : If the starting point of loop is at distance x from head, cycle length is c and the point where slow and fast meet is at distance y from the starting point, as we know the slow and fast starts at head and slow moves by 1 and fast moves by 2 from the start, we can say, 2*distance traveled by slow pointer = distance traveled by fast pointer. ==> 2*(x+y) = x + c + y ==> x = c-y Thus we can say that the distance of head to start of the loop is the same as the fast to start point of the loop. So if we update slow by head, and move slow and fast simultaneously then the point where we meet is the start point of the loop.
A minor correction factor would be that c is multiplied with n , which is length of the cycle, as there is no assurance that both slow and fast pointer collide during the second rotation itself. 2 * (x+y) = x + y + nc
@@bharath3387 They will definitely meet in the 2nd rotation as the initial distance from fast to slow is d(as Striver mentioned), which will always be less than the cycle length. And they meet in d steps as they fast to slow distance is decreasing by 1 with every step.
Damn I was blown away, literally. I was like, This is how the starting point is detected. As you said, I don't think anyone will teach us in this depth.
Absolutely a stunning video Literally I am following your playlist since many months, But I have covered LinkedList and Stack somewhere but still I sucked, literally you are awesome, now I need to watch Stacks and Queues for to be pro in them Thank you, so much dear brother,
honestly on any other youtube channel i dont see this type of explenation on intution behind this algorithm. literally every querry of mine about this algorithm get solved. you are genious bro. hatts of you....
I am an intern at Siemens and came back to this video for the proof even though I know the code. Thanks, Striver particularly for this amazing tutorial.
MY first yr is done and I have started dsa and little bit development also... My second year will start from 24 July by then how much should I cover so that I get a lead.... Plz answer if possible
@@anonymous13378I’m 2 years experienced and I’m starting DSA again.. it’s never too late you’re begun so early don’t lose the momentum keep it up and you will reach wherever you want if only you stay consistent..
ok right now i am at 12:39 and i saw the pseudocode and approach.About to watch the intuition with the sad fact in ma mind ki even tho i go through the method again and again...still i will forget.Another thing i want to say is i m stunned by the approach.Let's see what happens further.
Understood! For the people that didn't understand the demonstration, Neetcode explains this as well in his video of Floyd Cycle Detection. This is no shade, I love Striver, I just understood the demonstration better in Neetcode's video.
the explanation is phenomenal but yes It took me time cuz my ADHD ass can't concentrate on a single topic for a long time but I'm trying to improve and striver tussi great ho ji
I found Striver's intuition difficult to understand, so here is an alternative mathematical approach: Let, x = length outside the loop y = length from start of loop to meeting point z = length from meeting point to start of loop Now, distance travelled by slow pointer before meeting = x + y distance travelled by fast pointer before meeting = x + y + z + y = x + 2y + z Now Since, speed of fast = 2 * speed of slow (and time is constant) Therefore, distance travelled by fast pointer before meeting = 2 * distance travelled by slow pointer before meeting => x + 2y + z = 2 * (x + y) => x = z => length outside the loop = length from meeting point to start of loop Draw a LL on a paper, you will understand this easily.... If you like this way please like the comment....btw this is the 100th comment
@@dhruvchopra26 Let me tell you my experience and how this dsa help us in real world. See DSA Taught us to stay with problem and try to solve it. The more you stay with problem, more chances you will be able to solve that. Similarly in real world , when you will come across bugs and you try to fix those then you will have stay with bug , understand how, why, and from where it produced. And All you do is just debug the code to understand process. Ab isme sbse badi cheez ki tumhe pta bhi nhi chlega aur tumhe codebase ki poori information ho jaaegi , jaise jaise tum bug fix krte chle jaaoge. And there we have our biggest learning , codebase of thousands of lines of code and now we know which thing happening from which code.
In starting , I also did this mistake whenever I came across any bug I directly asked my senior but they refuse to tell me about how to fix that. In response to that they ask me to come up with some solution first and then they will tell me about the right one. And booom Now I know about the codebase completely.
Dammmmnnnn!!!! This man leaves no "Why?" unanswered!!! Wonderful job Striver...keep up the good work!!
Striver I desperately wants to know from where you learn these concepts and making this huge impact on us. Hats off you.
yeah me too
bro try some books and online resources and its all about experience i think
No one can beat striver🔥🔥on entire youtube, when it's come to DS and Algo. He is doing a remarkable thing.
i have been watching your dsa series since almost 1 month. this intuition shocked me... literally.. no youtuber or tutor teaches the way you teach. i really appreciate the way you teaches ... hats off sir.
Another way to put the intuition can be :
If the starting point of loop is at distance x from head, cycle length is c and the point where slow and fast meet is at distance y from the starting point, as we know the slow and fast starts at head and slow moves by 1 and fast moves by 2 from the start, we can say,
2*distance traveled by slow pointer = distance traveled by fast pointer.
==> 2*(x+y) = x + c + y ==> x = c-y
Thus we can say that the distance of head to start of the loop is the same as the fast to start point of the loop.
So if we update slow by head, and move slow and fast simultaneously then the point where we meet is the start point of the loop.
Wow, this really helped me put things into perspective, thanks for the explanation!!
A minor correction factor would be that c is multiplied with n , which is length of the cycle, as there is no assurance that both slow and fast pointer collide during the second rotation itself.
2 * (x+y) = x + y + nc
@@bharath3387 They will definitely meet in the 2nd rotation as the initial distance from fast to slow is d(as Striver mentioned), which will always be less than the cycle length. And they meet in d steps as they fast to slow distance is decreasing by 1 with every step.
This really helped Thank you
Thank you so much for the explaination.
Man of his words❤. I can't find anyone who is this much good with his concepts in DSA. U r the GOAT of DSA.
Striver isn't pregnant , but delivers faster
😂
wtf 🤣🤣🤣
😂😅
Kesi apmaan janak baatein kar raha he ladka ye
Ashleel hai ye londa
The entire video 10/10 but the intuition part is 100000/10. Hat's off Striver !❤🔥
The thought process behind the intuition was on point!
Damn I was blown away, literally. I was like, This is how the starting point is detected. As you said, I don't think anyone will teach us in this depth.
Absolutely a stunning video Literally I am following your playlist since many months, But I have covered LinkedList and Stack somewhere but still I sucked, literally you are awesome, now I need to watch Stacks and Queues for to be pro in them
Thank you, so much dear brother,
honestly on any other youtube channel i dont see this type of explenation on intution behind this algorithm. literally every querry of mine about this algorithm get solved. you are genious bro. hatts of you....
Understood..........Thanks a ton for the video...........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
The greatest video ever made on this topic by a human being
I am an intern at Siemens and came back to this video for the proof even though I know the code. Thanks, Striver particularly for this amazing tutorial.
MY first yr is done and I have started dsa and little bit development also... My second year will start from 24 July by then how much should I cover so that I get a lead.... Plz answer if possible
@@anonymous13378I’m 2 years experienced and I’m starting DSA again.. it’s never too late you’re begun so early don’t lose the momentum keep it up and you will reach wherever you want if only you stay consistent..
I would say cover array, linked list, strings common operations and question types and you will be good to appear for internship interviews.
This man actually got some balls in DSA🔥
Depth of Explanation is amazing. I mean this is just beautiful. Understood !
The explanation of why behind the logic 🔥
Sir you are the best teacher your way of teaching is absolutely good. ❤
Very well explained.....and in most of the questions we are playing with fast and slow ptr. Loved the series!!!!!
thank you striver. now i am able to discover patterns in problems and able to think for both brute and optimal solutions for them.
How do i even think of the optimal approach the way you do , just CRAZYYYY
very crystal clear concept dada .Thank you bhiya for all your hard work. very well understood.
Great Explanation. Finding it very difficult to understand this concept but you made it so easy. Thanks!!
Excellent explanation sir!! Thank you so much for these lectures!!
Awesome , your new videos are much better, update the link of videos in your tuf sde list, it is linked to old video
It's a simple math .. That is used in this algorithm
ok right now i am at 12:39 and i saw the pseudocode and approach.About to watch the intuition with the sad fact in ma mind ki even tho i go through the method again and again...still i will forget.Another thing i want to say is i m stunned by the approach.Let's see what happens further.
Ok watched it now, Blown away by the intuition, Thanks Raj dada.
This is what happens when a Pro coder is also having insane teaching skills.
Understood! For the people that didn't understand the demonstration, Neetcode explains this as well in his video of Floyd Cycle Detection. This is no shade, I love Striver, I just understood the demonstration better in Neetcode's video.
Thanks, after seeing your comments i watched that video from neetcode and understood
ek number lecture mast!!!!!!!!!!!!!!!!!!!!!!!! samj aa gya thanks!!!!!!!!!!!!!!!!
OMG, the intuition was on point!. Thank you striver jii
Great explanation ❤
Understood ! Thank you Striver 🙏
hi pretty
What an intuition man !
Congratulations on .6 million subscribers!!!!! 🎉❤🎉❤
.6💀
thanks sir, awesome explanation
16:30 Bro it can't happens always when slow will be at start then fast will be at L1 distance node
"Fast might rotate one circle"
the explanation is phenomenal but yes It took me time cuz my ADHD ass can't concentrate on a single topic for a long time but I'm trying to improve and striver tussi great ho ji
the proof was really well explained 👍
Good job, man. Thank you.
thanks Striver. You are awesome
nice explanation
at 17:30 if fast moves in distance(d) at speed of 2 then it becomes d/2 right then why is he saying d-2? Anyone pls say ?
suppose the d was 5, and the fast moves by 2, then after 1 moves the d become 3 (5-2). that's why d also become d-2.
I found Striver's intuition difficult to understand, so here is an alternative mathematical approach:
Let,
x = length outside the loop
y = length from start of loop to meeting point
z = length from meeting point to start of loop
Now, distance travelled by slow pointer before meeting = x + y
distance travelled by fast pointer before meeting = x + y + z + y = x + 2y + z
Now Since, speed of fast = 2 * speed of slow (and time is constant)
Therefore, distance travelled by fast pointer before meeting = 2 * distance travelled by slow pointer before meeting
=> x + 2y + z = 2 * (x + y)
=> x = z
=> length outside the loop = length from meeting point to start of loop
Draw a LL on a paper, you will understand this easily....
If you like this way please like the comment....btw this is the 100th comment
how can we be so sure that slow will never complete a cycle and fast completes only one cycle
sir you are the best
Best explanation
You are a champ man.
For the submission of the Leetcode we have to do minor changes in the code for the fast pointer.
Like what?
Super Explaination sir
Amazing Explanation!!!
Mind Blowing
Thank you🥰
best tutor, keep going sir.
also want you to teach development.
Understood sir very clear,thx sir
You're a Genius !
understood ❤
Easier solution could be :
class Solution {
public:
ListNode *detectCycle(ListNode *head) {
ListNode* temp=head;
long long data=1e6;
while(temp!=nullptr){
if(temp->val==1e6){
return temp;
}
temp->val=data;
temp=temp->next;
}
return nullptr;
}
};
Genius is all I can say .
Wow, how did one made this intuition for the very first time
Thank you striver !
understood!
Hey striver
What is the time complexity for hashing method in case of java?
Is O(2N) right?
superb that logic!!
Understood. Thanks for the video.
time complexity for the optimal approach is O(2N)?
superb sir 🤩
what is time complexity of optimal approach and how you found it?
Detailed explanation as always!
Thankyouuu Striver🤗
God tier content !!!!
What will be time complexity of optimal approach ?
Plz answer
Strivee bhai kya speed hai aapka😅
Vivekanand sir ka bhi u ppl can refer to understand the Intuition, if in case confusing lage
if you were my teacher i will be topped in all my semesters
Hey Striver
What notebook are you using for teaching 👀
Understood the intution. Such a great explanation. But how can one come up with such an optimal solution?Like how is it possible??
Best explanation 🤌🤌🔥
Understood sir!
love your videos
thank you so much.. really helped me a lot
Too intelligent 🧠
Understood, thank you.
The intuiton part 💯
UNDERSTOOD
Understoodddddd!!!!!!!!!!
How would someone came to these optimal approach at first glance (if not done before), in interviews?
No one can. That's why we are watching these. 😁
Exactly! Sometimes DSA feels like sab ratna padega tbhi kr payenge
@@dhruvchopra26 Let me tell you my experience and how this dsa help us in real world.
See DSA Taught us to stay with problem and try to solve it. The more you stay with problem, more chances you will be able to solve that.
Similarly in real world , when you will come across bugs and you try to fix those then you will have stay with bug , understand how, why, and from where it produced. And All you do is just debug the code to understand process.
Ab isme sbse badi cheez ki tumhe pta bhi nhi chlega aur tumhe codebase ki poori information ho jaaegi , jaise jaise tum bug fix krte chle jaaoge. And there we have our biggest learning , codebase of thousands of lines of code and now we know which thing happening from which code.
In starting , I also did this mistake whenever I came across any bug I directly asked my senior but they refuse to tell me about how to fix that. In response to that they ask me to come up with some solution first and then they will tell me about the right one.
And booom Now I know about the codebase completely.
thankyou
Understood✅🔥🔥
best explanation!
Thank you Bhaiya
Time complexity for optimal approach?
kinda understood
Thanks a lot Bhaiya !!
Understood
can u please explain how's the distance between slow and the collision point is d at time stamp 19:53
roger sir
why cant we do like this, like at the collision , if we take low->next->next->next it will be my ans ?
Understood 🙌🙌🙌
what will be the time complexity?
Please do string playlist .
Awesome!!
Man awesome!!