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🚀
@@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 ?
@@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.
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.
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??
Best explanation for the solution, neetcode doesnt come close at all.
So glad that you feel that way 😄
Sir please start a playlist of hard DSA problems.
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🚀
This channel is a gem. Thanks Nikhil for the wonderful explanation.
Glad to have teachers like you ❤
Wow! Brilliant explanation! You have helped me to finally demystify the fear around coding algorithm.
Your way of explanation!!! Thank you so much.
great explanation bro. Thanks for the video
Non forgettable explanation ...! Excellent
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)
Very good
@@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 ?
@@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.
Thank you Nikhil bhai, you helped me a lot with linkedlist problems.
very nicely explained
Such amazing content!! These videos are so well done. Thank you
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
great explanation you are doing great keep going
Even without dummy we can do this ??
Wow explaination
great Explaination
thanks a lot nikhil you are a gem
thankyou sir
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.
That is exactly why the dummy node helps. The first node from last is actually the first node that we have to remove
Amazing explanation❤
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.
// 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;
}
};
Thank you sooooooo much ❤❤
You're welcome 😊
Wow❤
Thank you for explaining. Can you please start a playlist of solving leetcode 75. It would be very helpfulto us.
once, I complete all the basic concepts...yes, I will start that playlist..otherwise it becomes hard to refer to those explanations
❤
@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 ?
yes, you can do it...but ask your interviewer first
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??
Yes we can, but then you are taking extra space. Ask your interviewer if you are allowed to do so.
@@nikoo28 OK sir thanks for your reply
In that dry run section in that while loop it'd be SecondPtr instead of SecondPtr.next
what do you mean? it should be secondPtr = secondPtr.next;
Can you please clarify?
@@nikoo28 they meant , while(secondPtr != NULL) not while(secondPtr.next != NULL)