Copy List with Random Pointer | Leetcode 138 | Linked List | Day-12

Sdílet
Vložit
  • čas přidán 23. 07. 2024
  • Timestamps:
    Problem explanation: 00:00
    Approaching the problem (Extra space) - 05:00
    Optimized approach : 11:00
    Complexity analysis: 29:15
    Clone Graph: • Clone Graph | Leetcode...
    Time Complexity : O(n)
    Space Complexity : O(1)
    Problem Link : leetcode.com/problems/copy-li...
    C++ Code Link : github.com/Ayu-99/Data-Struct...
    Python Code Link: github.com/Ayu-99/Data-Struct...
    Java Code Link : github.com/Ayu-99/Data-Struct...
    Please like, share and subscribe if you found the video useful. Feel free to ask in comments section if you have any doubts. :)
    #DataStructuresAndAlgorithms
    #CopyListWithRandomPointer
    #interviewpreparation
    Copy List with Random Pointer solution
    Copy List with Random Pointer Leetcode
    Copy List with Random Pointer C++
    Copy List with Random Pointer Java
    Copy List with Random Pointer Python
    🔥🔥🔥🔥👇👇👇
    Join telegram channel for more updates on placement preparation : t.me/AyushiSharmaDiscussionGroup
    Checkout the series: 🔥🔥🔥
    👉Interview Experiences : • Interview Experiences
    👉 Array: • Arrays
    👉 Linked List : • Linked List
    👉 Heap : • Heap
    👉 Recursion : • Recursion
    👉 Stack and Queue : • Stack And Queue
    👉 Greedy : • Greedy
    👉 Dynamic Programming : • Dynamic Programming
    👉 Leetcode contests : • Leetcode contests
    👉 Leetcode June Challenge : • Leetcode June Challenge
    👉 Leetcode July Challenge : • Leetcode July Challenge
    LIKE | SHARE | SUBSCRIBE 🔥🔥😊

Komentáře • 30

  • @mlLearning490
    @mlLearning490 Před rokem +1

    Thank you so much for the amazing explaination ...

  • @anamikaahmed4887
    @anamikaahmed4887 Před 2 lety +4

    The best explanation for this problem so far! Keep posting :)

  • @dineshkarankot2369
    @dineshkarankot2369 Před rokem

    amazing explanation

  • @vatsalkudecha2746
    @vatsalkudecha2746 Před 2 lety

    Amazing! I was able to code both approaches myself after your explanation. Thanks.

  • @mansigoyal4796
    @mansigoyal4796 Před 2 lety +1

    Understood in one go. Thankyou di :)

  • @AbhishekRaj-fo7rj
    @AbhishekRaj-fo7rj Před rokem

    Amazing! you made it easy🥰🥰

  • @sadashivshinde9150
    @sadashivshinde9150 Před 2 lety +2

    I wonder how does one get intution for second approach

  • @manthansrivastav9640
    @manthansrivastav9640 Před 2 lety

    nice explanantion

  • @shaileshbharti1026
    @shaileshbharti1026 Před 2 lety

    Great Explanation ...
    ⚡⚡👌

  • @Sanju22133
    @Sanju22133 Před 2 lety +1

    New Subscriber, Mam Ur Explaination is so nice and I understand this question very clearly. Also Please Mam make a video on multiplication of two linked list and return the output of multiplication as list.

    • @AyushiSharmaDSA
      @AyushiSharmaDSA  Před 2 lety

      Thank you so much🙂
      Sure, will make a video on it :)

  • @rajdave7357
    @rajdave7357 Před 2 lety

    Thanks

  • @pavanrajjagdale9369
    @pavanrajjagdale9369 Před 2 lety

    Thank you diii😊

  • @devendratumu1704
    @devendratumu1704 Před 2 lety +1

    I've written code for approach it is only working for unique values

  • @rackstar2
    @rackstar2 Před rokem

    The logic of your solution is completely sound.
    And i 100% understood the way it worked.
    But for some reason the Python version of the solution throws a runtime error on leetcode which i cant seem to understand why.

  • @amitsinha806
    @amitsinha806 Před 2 lety +1

    👍👍👍👍👍👍❤️❤️

  • @anamikaahmed4887
    @anamikaahmed4887 Před 2 lety

    The Java Code according to this solution:
    class Solution {
    public Node copyRandomList(Node head) {
    Node current = head;
    // creating a copied node beside each original node
    while(current!=null){
    Node newNode = new Node(current.val);
    Node temp = current.next;
    current.next = newNode;
    newNode.next = temp;

    current = temp;
    }
    // correcting all the pointers
    current = head;
    while(current!=null){
    if(current.random!=null){
    current.next.random = current.random.next;
    }
    current = current.next.next;
    }

    current= head;
    Node dummy = new Node(0);
    Node copy = dummy;
    Node copyTail = dummy;
    while(current!=null){
    Node temp = current.next.next;
    copy = current.next;
    copyTail.next = copy;
    copyTail = copy;

    //restore the original list
    current.next = temp;
    current = temp;
    }
    return dummy.next;
    }
    }