Copy List with Random Pointer | 2 Approaches | Clear Intuition | Dry Run | Microsoft| Leetcode - 138

  Рет қаралды 6,631

codestorywithMIK

codestorywithMIK

Күн бұрын

Пікірлер: 115
@dhairyachauhan6622
@dhairyachauhan6622 Жыл бұрын
In the realm of code and algorithms, we find, A teacher, Mike, with knowledge vast, combined. On this Teacher's Day, we celebrate his grace, As he guides us through the digital maze. He breaks down complexities with such ease, Inspiring us all, putting our minds at ease. On this special day, we send our praise, To Codestory's captain, in many ways. Happy teachers day brother 🙇‍♀🙇‍♀
@codestorywithMIK
@codestorywithMIK Жыл бұрын
You made my day. Thank you so much 🙏🙏🙏❤️❤️
@sharaabsingh
@sharaabsingh 9 ай бұрын
Yaar aap gajab insaan ho... Harr question itna simple kr doge toh interviewer kaha se question puchega? Galat baat hai sir ji, aise toh sab FAANG ke interviews nikaal lenge😆 Thank you yaar, bohot shaandaar explanation!!
@Tech_insider168
@Tech_insider168 Ай бұрын
I am visiting this channel for the first time. after seeing this video I have become a subscriber because sir, your explanation is very good i understand each and every line ❤️
@Greek_Bit_10
@Greek_Bit_10 Жыл бұрын
bhai aap ke jaise koi nhi explain karta hai Aap crysatl clear kar dete ho concept ko thanks bro ❤
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Means a lot ❤️
@kareni7572
@kareni7572 4 ай бұрын
Nice. Thanks for building intuition in both approaches! Makes it enjoyable 🎉
@harshikaagarwal6628
@harshikaagarwal6628 Жыл бұрын
I don't have words to express my gratitude to you. The impact you have made by your teachings is immense. Thanks for all the confidence and knowledge you have given. :)
@GouravSharma-tv2pi
@GouravSharma-tv2pi 7 ай бұрын
Whenever i stuck at problem , i directly came here 🤩🤩
@shreyyyc
@shreyyyc Жыл бұрын
Wish you a very happy teacher's day bhai. You're are the best teacher that's even being virtual. It's been 8 months I have been watching your daily videos and It always feels like ki mera bda bhai merko pdha rha h. Without a doubt your explanations are the best but your videos also delivers the ASMR experience, No loudness, relaxing voice, complex algorithms made easy and sometimes the tickling voice of your pen touching your Ipad screen. A good coding and ASMR experience altogether. Happy teacher's day!
@mdtouseeb264
@mdtouseeb264 Жыл бұрын
Ek number bro😊.....floor-->ceil☺
@bossmemes3308
@bossmemes3308 Жыл бұрын
I am really happy today to see improvements in myself. I have tried from scratch to solve this problem along with this problem I've solved the questions like how to clone single LL, then doubly LL and tried myself to solve it but failed because I was creating a new node for the random pointer. This video shown to me and I start to watch I have seen the concept of how the random pointer should work and I tried one more time before watching the video and literally I did it. Thankyou so much mike. :)
@codestorywithMIK
@codestorywithMIK Жыл бұрын
I am so so happy to hear that ❤️❤️❤️
@bossmemes3308
@bossmemes3308 Жыл бұрын
🙏❤️
@amitguptapc
@amitguptapc Жыл бұрын
2nd approach was just superb. And very well explained
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thank you 🙏🙏😇❤️
@035-harshitsingh7
@035-harshitsingh7 Жыл бұрын
Happy Teacher's day bhaiya...aapke karan hi jo knowledge hai so hai bhaiya aap nhi hote to bhut cheejon me clarity nhi aati...Kudos to your hardwork and consistency ✨🎉
@aayushranjan5572
@aayushranjan5572 Жыл бұрын
bhaiya apse bahut kuch sikhn ko milta h pls daily 3,4 vdo daley
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Sure. Will definitely try 🙏😇
@AAKIBVAHORA-ty4mk
@AAKIBVAHORA-ty4mk 6 ай бұрын
Appreciate the way you explain each detail with enthusiasm. I really admire you ;)
@chaitanya812
@chaitanya812 Жыл бұрын
abhi tk is question ko mai sabse tough smjta tha but ab nai thanks for your effort bhai
@codestorywithMIK
@codestorywithMIK Жыл бұрын
So glad to hear that ❤️🙏😇
@umeshbisht1054
@umeshbisht1054 Жыл бұрын
Happy teacher's day bhaiya and thanku for the second apporch ❤❤
@muntajir646
@muntajir646 4 ай бұрын
Best Explanation on the internet💌 Thank you so much.
@monikavaid5083
@monikavaid5083 5 ай бұрын
The way you explained the space complexity is really good 😇
@codestorywithMIK
@codestorywithMIK 5 ай бұрын
Glad it helped 😇
@krishankant3720
@krishankant3720 Жыл бұрын
It's been our pleasure to learn from u everyday ,happy teachers day 🎉🎉❤❤
@keertilata20
@keertilata20 Жыл бұрын
Happy Teachers Day, bhaiya... I hope everyone gets a teacher like you.
@avnish-wf8rv
@avnish-wf8rv Жыл бұрын
Happy Teachers Day, you gave us confidence in DS and made DS easier for us. Thanks a lot 🎉❤
@saurabhtiwari9614
@saurabhtiwari9614 Жыл бұрын
So beautiful explanation sir. Clear and cut explanation. N happy teacher's day to u sir🎉🎉🎉.
@souravjoshi2293
@souravjoshi2293 Жыл бұрын
Happy Teachers' Sir ji
@monty6393
@monty6393 Жыл бұрын
Hey brother!. Thanks for the video , the second approach was the key take away from the video ..
@kunaljoshi9262
@kunaljoshi9262 Жыл бұрын
Happy teachers day to our ultimate guru Mike Sir........😊
@floatingpoint7629
@floatingpoint7629 Жыл бұрын
thanks for the explanation. this is how i did it: var copyRandomList = function (head) { if (!head) return null const map = new Map(); map.set(null, null); const dfs = node => { if (map.has(node)) return map.get(node); const newNode = new Node(node.val); map.set(node, newNode); newNode.next = dfs(node.next); newNode.random = dfs(node.random); return newNode; } return dfs(head); } another approach: var copyRandomList = function (head) { if (!head) return null; let ptr = head; while (ptr) { const newNode = new Node(ptr.val); ptr.clone = newNode; ptr = ptr.next; } ptr = head; const newHead = ptr.clone; while (ptr) { ptr.clone.random = ptr.random?.clone ? ptr.random.clone : null; ptr.clone.next = ptr.next?.clone ? ptr.next.clone : null ptr = ptr.next; } ptr = head; while(ptr) { delete ptr.clone; ptr = ptr.next; } return newHead; }
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thanks a lot for sharing ❤️
@ishwarkoki1119
@ishwarkoki1119 Жыл бұрын
Happy teacher's Day MIK. Hopefully will meet someday
@aws_handles
@aws_handles 8 ай бұрын
Best explanation on this problem
@r.beditz3674
@r.beditz3674 Жыл бұрын
Happy teacher's day bhaiya ❤🙏🏻 aapke bina meri DSA achi hi nahi hoti. all thanks to you🙌🏻
@codestorywithMIK
@codestorywithMIK Жыл бұрын
It’s all your hard work 💪🙏❤️
@ajit287
@ajit287 Жыл бұрын
Nice Explanation !!! Especially for space part really loved it bro.... Happy teacher's Day.
@phoddaal7130
@phoddaal7130 Жыл бұрын
Happy Teacher’s Day Sir 😇 Thank you so much for putting so much efforts in your videos to help us. ❤️
@Tejaswi-xd4re
@Tejaswi-xd4re Жыл бұрын
Happy teacher's day sir.. After u feel better pls make the question list video sir which I was asking earlier
@daayush6654
@daayush6654 Жыл бұрын
I think technical term "Auxiliary space" use karte hai log, like what extra space apart from space taken by output is used by our approach. Which for first approach is O(n) and O(1) for second approach. But overall space complexity for both approaches would be O(n) based on the definition you explained
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Definitely. Actually it’s totally debatable. Whatever interviewer agrees for 😇
@2Deadly_
@2Deadly_ Жыл бұрын
Happy Teacher Day sir, You are such a great teacher. Making hard problems simple and easy to understand
@gauravbanerjee2898
@gauravbanerjee2898 10 ай бұрын
Best explanation fr this question on the internet ❣🔥🔥
@codestorywithMIK
@codestorywithMIK 10 ай бұрын
It means a lot. Thank you so much ❤️❤️
@mdfaizanraza3509
@mdfaizanraza3509 Жыл бұрын
Happy teacher's day Mazhar bhaijaan❤...aapko khabar nahi par aap ek video me bohot kuch seekha jate ho❤
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Means a lot ❤️🙏😇 Thank you ❤️❤️
@aman3210
@aman3210 Жыл бұрын
HAPPY TEACHER'S DAY BHAIYA ...LOVE YOUR TRUE & EASY EXPLAINATION ... THANKS++;
@086-jatinsharma8
@086-jatinsharma8 Жыл бұрын
Happy teacher's day sir..
@turing_machine544
@turing_machine544 Жыл бұрын
Happy Teachers day mik bhaiya, Thanks for existing , in the word full of wannabe dsa influencers , you are the only one who cares about your students. I admire you a lot , I was very confused last year about my dsa preparation and have no idea what to do , how to do and lack of motivation. Then accidentally i watched your yt video and it was one of my best decision ever. I can't really express how mu h i admire you. Once i will get the job i will come to meet you.❤❤❤
@mehulsharma1292
@mehulsharma1292 Жыл бұрын
Happy teacher's day sir 🙌
@abby_bytes
@abby_bytes Жыл бұрын
Happy Teachers Day MIK Guruji!
@nothingtolose682
@nothingtolose682 Жыл бұрын
happy teachers day mik bhai... love your content
@Mainak908
@Mainak908 Жыл бұрын
Happy teacher's day bhaiya❤❤❤🎉🎉🎉
@tutuimam3381
@tutuimam3381 Жыл бұрын
Happy teachers day
@Music-tp8gg
@Music-tp8gg Жыл бұрын
Happy teachers day guruji
@it-27arpit99
@it-27arpit99 Жыл бұрын
Happy teacher's day ❤
@ShivamKumar-zj8bp
@ShivamKumar-zj8bp Жыл бұрын
Happy Teacher's Day Bhaiya. Thank you so much for giving the push though your awesome explanation. ❤
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thank you ❤️🙏😇
@pabitrakb5291
@pabitrakb5291 Жыл бұрын
Happy teacher's day
@amanashishlakra9479
@amanashishlakra9479 Жыл бұрын
Happy Teacher day Bhaiya😃😃!! 🙏🙏🙏🙏
@jyotishmoydeka6804
@jyotishmoydeka6804 Жыл бұрын
Happy teacher's day bhaiya❤‍🔥❤‍🔥.I just can't express how much I am grateful to you. Btw my first ever research paper is published successfully yesterday😇. I am so happyyy.
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Wow. Congratulations ❤️💪💪 And thank you for your warm wishes ❤️❤️
@jyotishmoydeka6804
@jyotishmoydeka6804 Жыл бұрын
@@codestorywithMIK thank you bhaiya 🥰
@abhishekverma7604
@abhishekverma7604 11 ай бұрын
simillar question : Clone Graph.. Both have similarities , u have to hash the values before marking down the next connected node.
@abhaytiwari5991
@abhaytiwari5991 Жыл бұрын
Happy Teacher's day🎉 Mik bhai
@percyx29
@percyx29 Жыл бұрын
Happy Teacher's Day my Hero !
@HarshMishra-cp7tj
@HarshMishra-cp7tj Жыл бұрын
10K Soon Bhhaiya And Happy Teacher's Day
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thank you so much 😀
@prabhkiratsingh8490
@prabhkiratsingh8490 Жыл бұрын
Happy Teacher's Day Sir❤✨
@killshot57
@killshot57 Жыл бұрын
Happy teacher's day sir ❤️❤️❤️
@yashsaxena326
@yashsaxena326 Жыл бұрын
happy teachers day sir.
@footballcreativeeverywhere260
@footballcreativeeverywhere260 Жыл бұрын
Happy teacher's day Bhiya ❤️
@rajeevkumarsingh8719
@rajeevkumarsingh8719 Жыл бұрын
happy teacher's day bhaiya
@YashSinghal
@YashSinghal Жыл бұрын
thanks for making videos !!
@wearevacationuncoverers
@wearevacationuncoverers Жыл бұрын
Happy Teachers' Day LEGEND
@Aditrash-n5j
@Aditrash-n5j Жыл бұрын
Happy teachers day sir !!!
@bhartipatel7833
@bhartipatel7833 Жыл бұрын
Happy teacher's day bhaia 🎉😊 Hope you're well.
@doomhead9109
@doomhead9109 Жыл бұрын
I am late but Happy Teachers Day sir ❤❤
@cse080chandrasekhar9
@cse080chandrasekhar9 Жыл бұрын
happy teachers day sir
@thekindspill
@thekindspill Жыл бұрын
Happy Teachers' Day SIR
@shivam875S
@shivam875S 10 ай бұрын
crystal clear sir
@codestorywithMIK
@codestorywithMIK 10 ай бұрын
😇❤️🙏
@manaskhare412
@manaskhare412 Жыл бұрын
You're doing great work, hatsoff to you! It would be great, if you could add the link of the IPad notes. It would be easy for us, if we want revision in the future.
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Hello Manas, Sure thing. I will add ipad notes link too.
@manaskhare412
@manaskhare412 Жыл бұрын
@@codestorywithMIK thanks 😊
@AnandKumar-kz3ls
@AnandKumar-kz3ls Жыл бұрын
i think space complexity should be O(N) but if interviewer said you have to build it without using any data structure like map , sets then this will be the optimal and best approch
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Indeed ❤️❤️
@Lucifer0872
@Lucifer0872 Жыл бұрын
Happy teachers day bhaiya
@anuppatankar4294
@anuppatankar4294 Жыл бұрын
Happy Teachers Day 🤝
@Rajdweep
@Rajdweep Жыл бұрын
happy teachers' day bro❤❤
@dayashankarlakhotia4943
@dayashankarlakhotia4943 Жыл бұрын
Happy teachers day .for your guidance I wrote this code. public class solution { public Node copy Random List(Node head){ if(head ==null)return null; Hash map mpp=new Hash map (); Node cur=head; while (cur!=null){ mp.put (cur,new Node (cur. val)); cur=cur.next; } cur=head; while (cur!=null){ mpp.get (cur).next =mpp.get(cur. next); mpp.get (cur).random =mpp.get (cur. random); cur=cur. next; } return mpp.get(head); } }; 2nd approach. Public class solution { public Node copy Random List(Node head){ if(head ==null)return null; Node cur =head; while (cur!=null){ Node. new. node=new Node (cur.val,cur.next); cur.next =new. node; cur=new. node.next; } cur =head; while (cur!=null){ if(cur. random!=null){ cur.next. random =cur. random. next; } cur =cur. next!=null? cur. next. next:null; } Node. old_ head =head; Node. new _head =head. next; Node. prev=old_head; Node. cur =new _head; while (prev!=null){ prev. next =prev. next. next; cur.next =cur.next.next !=null?cur. next. next:null; prev =prev. next; cur=cur.next; } return new _head; } }; thanks 🎉❤😮
@Samtoosoon
@Samtoosoon 3 ай бұрын
8:35
@nagmakhan672
@nagmakhan672 Жыл бұрын
Happy Teacher’s Day ❤
@TheBusaSinger
@TheBusaSinger Жыл бұрын
Happy Teacher’s Day! 😇
@ugcwithaddi
@ugcwithaddi Жыл бұрын
Happy Teachers’ Day ❤
@codeandtalk6
@codeandtalk6 Жыл бұрын
❤❤
@codeofcoffee8722
@codeofcoffee8722 Жыл бұрын
👌🏼
@taneyasoni
@taneyasoni Жыл бұрын
5/30
@deepjyotidas37
@deepjyotidas37 Жыл бұрын
Bhaiya I want to know your intuition building ,if you get a random question which is not seen previously, and also if you can't figure out how to solve it after giving a lot of time ,What is your approach after that to find the solution?
@AlishaKhan-ww3io
@AlishaKhan-ww3io Жыл бұрын
legend
@cacklouncle
@cacklouncle Жыл бұрын
Pehle approach mein extra space kaise hua woh create toh ek baar hi kiya hai, chahe result mein use karen ya map mn rakhen
@codestorywithMIK
@codestorywithMIK Жыл бұрын
In the first approach, we used map to store the nodes. That’s O(n) extra space we used
@abhishekverma7604
@abhishekverma7604 11 ай бұрын
but data is crucial part of software development,in second approach we are tampering data,is it correct to do so...
@codestorywithMIK
@codestorywithMIK 11 ай бұрын
I totally agree with you Abhishek. Actually it totally depends on what the interviewer wants from you. If they deliberately want you to solve that way (they are fine with data tampering) then you can go ahead with 2nd approach
@39_jatinjain4
@39_jatinjain4 Жыл бұрын
Que-Jump game class Solution { public: bool sol(int idx,vector& nums,int n,vector&dp){ // base case if(idx==n-1) return true; if(idx>=n) return false; if(dp[idx]!=-1) return dp[idx]; bool ans=false; for(int i=1;i
@percyx29
@percyx29 Жыл бұрын
Sir face reveal when? hehe
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Waiting for Ted Talk invitation 😉
@AbhishekGupta-ej3vw
@AbhishekGupta-ej3vw Жыл бұрын
Happy teachers day @ codewithmik
@jagadeeshp1163
@jagadeeshp1163 Жыл бұрын
""" # Definition for a Node. class Node: def __init__(self, x: int, next: 'Node' = None, random: 'Node' = None): self.val = int(x) self.next = next self.random = random """ class Solution: def copyRandomList(self, head: 'Optional[Node]') -> 'Optional[Node]': # add new node thead=head curr=head while(thead): new_node=Node(thead.val) thead=thead.next curr.next=new_node new_node.next=thead curr=thead # random pointer work thead=head while(thead and thead.next): if thead.random==None: thead.next.random=None else: thead.next.random=thead.random.next thead=thead.next.next #break to 2 ll new_head=head.next temp1=new_head while(head and temp1): if head.next==None: head.next=None else: head.next=head.next.next if temp1.next==None: temp1.next=None else: temp1.next=temp1.next.next return new_head TLE i code is giving TLE because of infinte while loop Can someone help me finding the error
@j_ourney25
@j_ourney25 Жыл бұрын
Happy teacher's day sir❤
@tutuimam3381
@tutuimam3381 Жыл бұрын
❤❤❤
@AnkitaKumari-if7lk
@AnkitaKumari-if7lk Жыл бұрын
Happy teacher's day bhaiya😊
СКОЛЬКО ПАЛЬЦЕВ ТУТ?
00:16
Masomka
Рет қаралды 3,5 МЛН
Odd Even Linked List - (Microsoft, Amazon) : Explanation ➕ Live Coding
22:04
Copy List with Random Pointer - Linked List - Leetcode 138
10:07