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

Sdílet
Vložit
  • čas přidán 20. 08. 2024

Komentáře • 43

  • @sreeharsharaveendra289
    @sreeharsharaveendra289 Před 7 měsíci +6

    Best explanation for the solution, neetcode doesnt come close at all.

  • @AadeshKulkarni
    @AadeshKulkarni Před 6 měsíci +2

    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🚀

  • @sachinsoma5757
    @sachinsoma5757 Před 8 měsíci +3

    This channel is a gem. Thanks Nikhil for the wonderful explanation.

  • @technicalguy.
    @technicalguy. Před 8 měsíci +1

    Glad to have teachers like you ❤

  • @tundeadebanjo6579
    @tundeadebanjo6579 Před 2 měsíci

    Wow! Brilliant explanation! You have helped me to finally demystify the fear around coding algorithm.

  • @Muhammad_Kabil
    @Muhammad_Kabil Před 2 měsíci +1

    Your way of explanation!!! Thank you so much.

  • @wilberrosales6345
    @wilberrosales6345 Před měsícem +1

    great explanation bro. Thanks for the video

  • @jaydeepvasoya6243
    @jaydeepvasoya6243 Před 4 měsíci

    Non forgettable explanation ...! Excellent

  • @shivraj940
    @shivraj940 Před 9 měsíci

    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  Před 9 měsíci

      Very good

    • @shivraj940
      @shivraj940 Před 9 měsíci

      @@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  Před 6 měsíci

      @@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 Před 5 měsíci

    Thank you Nikhil bhai, you helped me a lot with linkedlist problems.

  • @sanjeets93
    @sanjeets93 Před 20 hodinami

    very nicely explained

  • @robertnant1264
    @robertnant1264 Před 6 měsíci

    Such amazing content!! These videos are so well done. Thank you

  • @Pontiff03
    @Pontiff03 Před 2 měsíci

    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 Před 6 měsíci +1

    great explanation you are doing great keep going

  • @121sarthkumar4
    @121sarthkumar4 Před 3 měsíci +1

    Even without dummy we can do this ??

  • @Aspiringactor02
    @Aspiringactor02 Před 21 dnem

    Wow explaination

  • @parthmodi2028
    @parthmodi2028 Před 7 měsíci +1

    great Explaination

  • @tasniatahsin8637
    @tasniatahsin8637 Před 5 měsíci

    thanks a lot nikhil you are a gem

  • @sreejasree7427
    @sreejasree7427 Před 3 dny

    thankyou sir

  • @lookahead279
    @lookahead279 Před 5 měsíci

    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 Před 5 měsíci

      That is exactly why the dummy node helps. The first node from last is actually the first node that we have to remove

  • @deepaliyadav6444
    @deepaliyadav6444 Před 4 měsíci

    Amazing explanation❤

  • @jritzeku
    @jritzeku Před 3 měsíci

    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.

  • @himanshusingh8693
    @himanshusingh8693 Před 7 měsíci +1

    // 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;
    }
    };

  • @JustMeItsMMN
    @JustMeItsMMN Před 3 měsíci

    Thank you sooooooo much ❤❤

    • @nikoo28
      @nikoo28  Před 3 měsíci

      You're welcome 😊

  • @ssss22144
    @ssss22144 Před měsícem

    Wow❤

  • @srinivas1694
    @srinivas1694 Před 9 měsíci

    Thank you for explaining. Can you please start a playlist of solving leetcode 75. It would be very helpfulto us.

    • @nikoo28
      @nikoo28  Před 9 měsíci +2

      once, I complete all the basic concepts...yes, I will start that playlist..otherwise it becomes hard to refer to those explanations

  • @THOSHI-cn6hg
    @THOSHI-cn6hg Před 27 dny

  • @naveenkumarkota2090
    @naveenkumarkota2090 Před 6 měsíci

    @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  Před 6 měsíci

      yes, you can do it...but ask your interviewer first

  • @Karthik-fl4cq
    @Karthik-fl4cq Před 9 měsíci

    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  Před 8 měsíci

      Yes we can, but then you are taking extra space. Ask your interviewer if you are allowed to do so.

    • @Karthik-fl4cq
      @Karthik-fl4cq Před 8 měsíci

      @@nikoo28 OK sir thanks for your reply

  • @ayandutta9758
    @ayandutta9758 Před 7 měsíci

    In that dry run section in that while loop it'd be SecondPtr instead of SecondPtr.next

    • @nikoo28
      @nikoo28  Před 7 měsíci

      what do you mean? it should be secondPtr = secondPtr.next;
      Can you please clarify?

    • @Twintowers9.11
      @Twintowers9.11 Před 5 měsíci

      @@nikoo28 they meant , while(secondPtr != NULL) not while(secondPtr.next != NULL)