Remove Nth Node from End of List - Oracle Interview Question - Leetcode 19

preview_player
Показать описание


0:00 - Read the problem
1:10 - Drawing solution
4:20 - Coding solution

leetcode 19

#neetcode #apple #python
Рекомендации по теме
Комментарии
Автор

Hands down the best explanation I've seen...and it's in Python!

mshutube
Автор

Dummy node is actually not required if we run the loops till 'while right.next'. The reason we are using a dummy node is to handle the special case when we have to remove the first (head) node in a list of length 2

DHAiRYA
Автор

You'll be the reason I get my first SWE Internship

dillondalton
Автор

To the point, concise, not bullshit. Your video deserves more rewards!

rossli
Автор

Upvoted it the moment you finished explaining and started still fresh as in 2022

priyanshmathur
Автор

Great channel for programmers this channel has great potential....

yogeshgupta
Автор

I literally smiled after learning about the trick here! Amazing!!!

aniruddhashahapurkar
Автор

Nice! Sir, I just love the way you explain the answers.
I think we can also stop the iteration when R.next == nil so our L will be at position where we wanted.
Then we won't need dummy node.

samchopra
Автор

Best explanation for this one I've seen, thanks

ryanwest
Автор

Can be done in one while loop also:


def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]:
dummy = ListNode(0, head)
first = dummy
second = head

while second:
if n > 0:
second = second.next
n -= 1
else:
second = second.next
first = first.next

first.next = first.next.next
return head

shikhar
Автор

super clear explanation of this! thank you so much

jaredrodriguez
Автор

Thank you very much for your clear explanation. I really love NeetCode.
One feedback: Instead of playing the youtube video on a popup, I think you can open YouTube video directly when the "camera" button is clicked.
It would be easier for me and other people to like the videos :D

haphamdev
Автор

Hats off to you my guy... The best explanation I've watched so far. You gained a new subscriber!

gawi
Автор

Thanks after your explanation, solution become easy understandable

Alex-ywsn
Автор

Finding nth mode from the end of a linkedlist, can reverse the list and get a pointer, or can use two pointers, the space between them is n and move them forward at the same speed. When one reaches the end, the other will be at the nth element from the end

mostinho
Автор

wow thank you for your clear explanation!! love it!

amberbai
Автор

Great explanation! Instead of using a dummy we can just store prev of left and if left is None we can `return left.next` else we can `prev.next = prev.next.next`

altusszawlowski
Автор

This is a beautiful explanation, thank you

dilln
Автор

Wow, I finally understand this. Thanks!

EurekaSeen
Автор

Loved how the Dummy head node technique removes the need to handle several edge cases, like when the nth node is the original head.

yunierperez