No video

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

  Рет қаралды 8,487

Nikhil Lohia

Nikhil Lohia

Күн бұрын

Пікірлер: 45
@sreeharsharaveendra289
@sreeharsharaveendra289 8 ай бұрын
Best explanation for the solution, neetcode doesnt come close at all.
@nikoo28
@nikoo28 7 ай бұрын
So glad that you feel that way 😄
@urvashichaurasia6284
@urvashichaurasia6284 Ай бұрын
Sir please start a playlist of hard DSA problems.
@tundeadebanjo6579
@tundeadebanjo6579 2 ай бұрын
Wow! Brilliant explanation! You have helped me to finally demystify the fear around coding algorithm.
@sachinsoma5757
@sachinsoma5757 9 ай бұрын
This channel is a gem. Thanks Nikhil for the wonderful explanation.
@AadeshKulkarni
@AadeshKulkarni 6 ай бұрын
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🚀
@technicalguy.
@technicalguy. 8 ай бұрын
Glad to have teachers like you ❤
@wilberrosales6345
@wilberrosales6345 Ай бұрын
great explanation bro. Thanks for the video
@Muhammad_Kabil
@Muhammad_Kabil 3 ай бұрын
Your way of explanation!!! Thank you so much.
@jaydeepvasoya6243
@jaydeepvasoya6243 5 ай бұрын
Non forgettable explanation ...! Excellent
@shayannafees9936
@shayannafees9936 Күн бұрын
best explanation ever !!!!
@sanjeets93
@sanjeets93 16 күн бұрын
very nicely explained
@shivraj940
@shivraj940 9 ай бұрын
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 9 ай бұрын
Very good
@shivraj940
@shivraj940 9 ай бұрын
@@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 6 ай бұрын
@@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.
@atanukundu_10
@atanukundu_10 6 ай бұрын
Thank you Nikhil bhai, you helped me a lot with linkedlist problems.
@robertnant1264
@robertnant1264 6 ай бұрын
Such amazing content!! These videos are so well done. Thank you
@Pontiff03
@Pontiff03 2 ай бұрын
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
@uxoyplayz3373
@uxoyplayz3373 7 ай бұрын
great explanation you are doing great keep going
@Aspiringactor02
@Aspiringactor02 Ай бұрын
Wow explaination
@121sarthkumar4
@121sarthkumar4 4 ай бұрын
Even without dummy we can do this ??
@parthmodi2028
@parthmodi2028 7 ай бұрын
great Explaination
@lookahead279
@lookahead279 6 ай бұрын
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 6 ай бұрын
That is exactly why the dummy node helps. The first node from last is actually the first node that we have to remove
@srinivas1694
@srinivas1694 10 ай бұрын
Thank you for explaining. Can you please start a playlist of solving leetcode 75. It would be very helpfulto us.
@nikoo28
@nikoo28 9 ай бұрын
once, I complete all the basic concepts...yes, I will start that playlist..otherwise it becomes hard to refer to those explanations
@tasniatahsin8637
@tasniatahsin8637 6 ай бұрын
thanks a lot nikhil you are a gem
@deepaliyadav6444
@deepaliyadav6444 5 ай бұрын
Amazing explanation❤
@jritzeku
@jritzeku 4 ай бұрын
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.
@JustMeItsMMN
@JustMeItsMMN 4 ай бұрын
Thank you sooooooo much ❤❤
@nikoo28
@nikoo28 3 ай бұрын
You're welcome 😊
@sreejasree7427
@sreejasree7427 18 күн бұрын
thankyou sir
@Karthik-fl4cq
@Karthik-fl4cq 9 ай бұрын
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 8 ай бұрын
Yes we can, but then you are taking extra space. Ask your interviewer if you are allowed to do so.
@Karthik-fl4cq
@Karthik-fl4cq 8 ай бұрын
@@nikoo28 OK sir thanks for your reply
@ssss22144
@ssss22144 2 ай бұрын
Wow❤
@naveenkumarkota2090
@naveenkumarkota2090 7 ай бұрын
@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 6 ай бұрын
yes, you can do it...but ask your interviewer first
@THOSHI-cn6hg
@THOSHI-cn6hg Ай бұрын
@ayandutta9758
@ayandutta9758 7 ай бұрын
In that dry run section in that while loop it'd be SecondPtr instead of SecondPtr.next
@nikoo28
@nikoo28 7 ай бұрын
what do you mean? it should be secondPtr = secondPtr.next; Can you please clarify?
@Twintowers9.11
@Twintowers9.11 6 ай бұрын
@@nikoo28 they meant , while(secondPtr != NULL) not while(secondPtr.next != NULL)
@himanshusingh8693
@himanshusingh8693 8 ай бұрын
// 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; } };
@yomamasofat413
@yomamasofat413 14 күн бұрын
man this is a hack I dont know what this teaches. Actually a lot of leetcode solutions are hacks. Like the dp ones
I Took a LUNCHBAR OFF A Poster 🤯 #shorts
00:17
Wian
Рет қаралды 14 МЛН
PEDRO PEDRO INSIDEOUT
00:10
MOOMOO STUDIO [무무 스튜디오]
Рет қаралды 24 МЛН
Blue Food VS Red Food Emoji Mukbang
00:33
MOOMOO STUDIO [무무 스튜디오]
Рет қаралды 32 МЛН
SPONGEBOB POWER-UPS IN BRAWL STARS!!!
08:35
Brawl Stars
Рет қаралды 24 МЛН
DSA (Data Structures and Algorithms) for Campus Placements - Day 1
2:10:35
ExcelR Solutions
Рет қаралды 12 М.
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 199 М.
I Took a LUNCHBAR OFF A Poster 🤯 #shorts
00:17
Wian
Рет қаралды 14 МЛН