Copy List with Random Pointer | Leetcode 138 | Linked List | Day-12
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 🔥🔥😊
Thank you so much for the amazing explaination ...
The best explanation for this problem so far! Keep posting :)
Thank you so much Anamika :)
amazing explanation
Amazing! I was able to code both approaches myself after your explanation. Thanks.
Awsm Vatsal :)
Understood in one go. Thankyou di :)
Welcome Mansi :)
Amazing! you made it easy🥰🥰
Thank you Abhishek 🥰
I wonder how does one get intution for second approach
Yes :)
nice explanantion
Thank you 😊
Great Explanation ...
⚡⚡👌
Thanks Sailesh :)
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.
Thank you so much🙂
Sure, will make a video on it :)
Thanks
Welcome Raj :)
Thank you diii😊
Welcome Pavanraj :)
I've written code for approach it is only working for unique values
Yeah. Thanks for sharing :)
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.
👍👍👍👍👍👍❤️❤️
Thanks Amit :)
@@AyushiSharmaDSA your welcome😊😊😍
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;
}
}
Thanks for sharing :)