Master Data Structures & Algorithms For FREE at AlgoMap.io!
@sajinreyans33293 ай бұрын
The behind and ahead that u just used 1.why did you use it 2. Can I use this algorithm anywhere else 3. Does this algorithm have any other name
@yvettcodesАй бұрын
@@sajinreyans3329 He used the behind and ahead variable as a way to set up a gap between the nodes at the correct distance. Notice how once he adjusted the Ahead variable in the initial for loop, he then moved both ahead and behind until ahead reached the very end of the linked list (ahead = None). If you count the distance between Ahead and Behind after he's corrected their positions, you'll notice that it is now n+1- ensuring that B is in the correct position for our goal of deleting a target node. Hope this helps!
@zhihangcheng10834 ай бұрын
Elegent explaination!
@kubs116229 күн бұрын
made way more sense to me when i though of it as l, r instead of ahead, behind
@yvettcodesАй бұрын
I solved this problem differently, but I love your solution more! Thanks for the explanation. If you ever read this, could you please make a video for 1721. Swapping Nodes in a Linked List? Thanks a bunch, Greg!
@akshatsingh9830Ай бұрын
which sheet or roadmap are u following
@yvettcodesАй бұрын
@@akshatsingh9830 I'm not following anyone's specific roadmap, I am following Codecademy's DSA course to learn about the topic, then trying to do at least 8-10 problems for each of varying difficulty. Greg actually has a roadmap for leetcode problems though, and I plan to prioritize those questions and Blind/Grind75 questions for each topic as I learn.
@habeebah61352 ай бұрын
Hello, does the while loop get added as o(m+n). Why not? Worst case scenario it could go n-1 times right if the n value is 1. I do not understand why it is just o(m) here. Thank you
@mmm-ie5ws2 ай бұрын
how does changing the behind variable change the summy variable?
@yvettcodesАй бұрын
What do you mean? The behind variable does not change the dummy variable in this scenario. Behind is only a pointer that enables us to access the correct nodes for deleting our target node.