Remove nth node from end of Linked List (LeetCode 19) | A very very easy solution

  Рет қаралды 10,282

Nikhil Lohia

Nikhil Lohia

Күн бұрын

Пікірлер: 50
@Humanityplease777
@Humanityplease777 Ай бұрын
i saw 2videos previously explaining the solution but didnt understood at all.......thank you so much for making us understand in a very very simple way
@sachinsoma5757
@sachinsoma5757 11 ай бұрын
This channel is a gem. Thanks Nikhil for the wonderful explanation.
@sreeharsharaveendra289
@sreeharsharaveendra289 10 ай бұрын
Best explanation for the solution, neetcode doesnt come close at all.
@nikoo28
@nikoo28 10 ай бұрын
So glad that you feel that way 😄
@urvashichaurasia6284
@urvashichaurasia6284 3 ай бұрын
Sir please start a playlist of hard DSA problems.
@technicalguy.
@technicalguy. 11 ай бұрын
Glad to have teachers like you ❤
@tundeadebanjo6579
@tundeadebanjo6579 5 ай бұрын
Wow! Brilliant explanation! You have helped me to finally demystify the fear around coding algorithm.
@AadeshKulkarni
@AadeshKulkarni 9 ай бұрын
What I like about your videos is how you explain the brute force approach first and then explain the optimised solution. Introducing brute force solutions to noobs like me gives us some confidence and with that confidence + your simplicity of explaining the optimised solution works like charm, baba Beautiful! I also like how the structure is consistent across every video that you upload. Keep rising Nikhil🚀
@Muhammad_Kabil
@Muhammad_Kabil 5 ай бұрын
Your way of explanation!!! Thank you so much.
@jaydeepvasoya6243
@jaydeepvasoya6243 7 ай бұрын
Non forgettable explanation ...! Excellent
@robertnant1264
@robertnant1264 9 ай бұрын
Such amazing content!! These videos are so well done. Thank you
@atanukundu_10
@atanukundu_10 8 ай бұрын
Thank you Nikhil bhai, you helped me a lot with linkedlist problems.
@etidaya7119
@etidaya7119 2 ай бұрын
Very easy solution . Thanks !!
@shivraj940
@shivraj940 Жыл бұрын
Great explanation👍 . For removing nth from start, we can simply iterate (n-1)th node and map n-1 -> n+1. TC : O(n) and SC : O(1)
@nikoo28
@nikoo28 Жыл бұрын
Very good
@shivraj940
@shivraj940 Жыл бұрын
@@nikoo28 can you please explain more on the usage of dummy node ? like when we get index out of bound , etc and what’s the problem we face without using dummy node ?
@nikoo28
@nikoo28 9 ай бұрын
@@shivraj940i can talk about it in a video. But generally, a dummy nodes all those null pointer exceptions. And you can get rid of it anytime you want.
@shayannafees9936
@shayannafees9936 2 ай бұрын
best explanation ever !!!!
@elaf7092
@elaf7092 5 күн бұрын
really good explanation
@wilberrosales6345
@wilberrosales6345 4 ай бұрын
great explanation bro. Thanks for the video
@sanjeets93
@sanjeets93 3 ай бұрын
very nicely explained
@parthmodi2028
@parthmodi2028 10 ай бұрын
great Explaination
@uxoyplayz3373
@uxoyplayz3373 10 ай бұрын
great explanation you are doing great keep going
@kash1903
@kash1903 Ай бұрын
Bro this code is very help full in LeetCode it shows error , In the for Loop (i
@deepaliyadav6444
@deepaliyadav6444 7 ай бұрын
Amazing explanation❤
@tasniatahsin8637
@tasniatahsin8637 8 ай бұрын
thanks a lot nikhil you are a gem
@Aspiringactor02
@Aspiringactor02 3 ай бұрын
Wow explaination
@121sarthkumar4
@121sarthkumar4 7 ай бұрын
Even without dummy we can do this ??
@srinivas1694
@srinivas1694 Жыл бұрын
Thank you for explaining. Can you please start a playlist of solving leetcode 75. It would be very helpfulto us.
@nikoo28
@nikoo28 Жыл бұрын
once, I complete all the basic concepts...yes, I will start that playlist..otherwise it becomes hard to refer to those explanations
@Pontiff03
@Pontiff03 5 ай бұрын
Make an Adjustment to the code in while moving the secondPtr... set the limits of the for loop to be from i=1 to i
@lookahead279
@lookahead279 9 ай бұрын
at 9:20 we just have one node, so n should be n=0 . If n=1 then we will have exception . while n=1 , you are removing 8 not 4 in the previous example.
@nikoo2805
@nikoo2805 9 ай бұрын
That is exactly why the dummy node helps. The first node from last is actually the first node that we have to remove
@Karthik-fl4cq
@Karthik-fl4cq Жыл бұрын
Nice explanation sir 👍. Can we store all the pointers in a arraylist and storing its length in one ireration and mapping pointer of that index(len-n) to its next. Is that approach correct sir??
@nikoo28
@nikoo28 11 ай бұрын
Yes we can, but then you are taking extra space. Ask your interviewer if you are allowed to do so.
@Karthik-fl4cq
@Karthik-fl4cq 11 ай бұрын
@@nikoo28 OK sir thanks for your reply
@jritzeku
@jritzeku 7 ай бұрын
Can you explain dummy node logic for following case where head is deleted? 1->2->3->4->null , n=4 ....basically removes head node: PSEUDO code: -run first loop to advance 'right; as far as n allows dummy->1->2->3->4(second)->null. //second goes to tail -on second loop , advance 'left' as far as we can dummy(first)->1->2->3->4->null //first stays at dummy .. -our target deletion node ends up being the head node1 first.next =first.next.next dummy->1->2(first.next)->3->4->null HOW does dummy.next give u node 2? Doesn't it point to original head? The only thing that could make sense is firstPtr' serves as an alias to dummy but that logic fails becuase then we should be able to return left.next as final answer. This passes test case for where head node is deleted but not where non head node is deleted.
@sreejasree7427
@sreejasree7427 3 ай бұрын
thankyou sir
@THOSHI-cn6hg
@THOSHI-cn6hg 4 ай бұрын
@JustMeItsMMN
@JustMeItsMMN 6 ай бұрын
Thank you sooooooo much ❤❤
@nikoo28
@nikoo28 6 ай бұрын
You're welcome 😊
@ssss22144
@ssss22144 5 ай бұрын
Wow❤
@naveenkumarkota2090
@naveenkumarkota2090 9 ай бұрын
@nikhi if not the case of just one traveal can i reverse the linked list and delete it from the first and return the new linkedlist ?
@nikoo28
@nikoo28 9 ай бұрын
yes, you can do it...but ask your interviewer first
@himanshusingh8693
@himanshusingh8693 11 ай бұрын
// without dummy node class Solution { public: ListNode* removeNthFromEnd(ListNode* head, int n) { ListNode*start=head; ListNode*end=head; while(n--) { end=end->next; } if(end==NULL)return head->next; while(end->next!=NULL) { start=start->next; end=end->next; } start->next=start->next->next; return head; } };
@ayandutta9758
@ayandutta9758 10 ай бұрын
In that dry run section in that while loop it'd be SecondPtr instead of SecondPtr.next
@nikoo28
@nikoo28 10 ай бұрын
what do you mean? it should be secondPtr = secondPtr.next; Can you please clarify?
@Twintowers9.11
@Twintowers9.11 8 ай бұрын
@@nikoo28 they meant , while(secondPtr != NULL) not while(secondPtr.next != NULL)
@NandagopanPattayil
@NandagopanPattayil 25 күн бұрын
list.remove(list.size()-n); ???
@yomamasofat413
@yomamasofat413 3 ай бұрын
man this is a hack I dont know what this teaches. Actually a lot of leetcode solutions are hacks. Like the dp ones
Remove Nth Node From End of List | 1 Pass | 2 Pass | Leetcode 19
21:30
codestorywithMIK
Рет қаралды 4,8 М.