Remove Nth Node from End of List - Leetcode 19 - Linked Lists (Python)

  Рет қаралды 5,933

Greg Hogg

Greg Hogg

Күн бұрын

Пікірлер: 12
@GregHogg
@GregHogg 5 ай бұрын
Master Data Structures & Algorithms For FREE at AlgoMap.io!
@sajinreyans3329
@sajinreyans3329 3 ай бұрын
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
@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!
@zhihangcheng1083
@zhihangcheng1083 4 ай бұрын
Elegent explaination!
@kubs1162
@kubs1162 29 күн бұрын
made way more sense to me when i though of it as l, r instead of ahead, behind
@yvettcodes
@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
@akshatsingh9830 Ай бұрын
which sheet or roadmap are u following
@yvettcodes
@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.
@habeebah6135
@habeebah6135 2 ай бұрын
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-ie5ws
@mmm-ie5ws 2 ай бұрын
how does changing the behind variable change the summy variable?
@yvettcodes
@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.
@harshapavanteja58
@harshapavanteja58 5 ай бұрын
hi
L8. Remove Nth Node from the end of the LinkedList | Multiple Approaches
16:23
REAL or FAKE? #beatbox #tiktok
01:03
BeatboxJCOP
Рет қаралды 18 МЛН
Cheerleader Transformation That Left Everyone Speechless! #shorts
00:27
Fabiosa Best Lifehacks
Рет қаралды 16 МЛН
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 193 М.
How I Mastered Data Structures and Algorithms in 8 Weeks
15:46
Aman Manazir
Рет қаралды 153 М.
Merge Two Sorted Lists - Leetcode 21 - Linked Lists (Python)
9:41
Clone Graph - Leetcode 133 - Graphs (Python)
13:38
Greg Hogg
Рет қаралды 4,9 М.
How I Approach a New Leetcode Problem (live problem solving)
25:31
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 767 М.
Linked List Cycle - Leetcode 141 - Linked Lists (Python)
7:47
70% of Programmers can't solve this LeetCode Easy Question
7:32
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 685 М.
REAL or FAKE? #beatbox #tiktok
01:03
BeatboxJCOP
Рет қаралды 18 МЛН