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 🙇♀🙇♀
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!!
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 ❤️
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. :)
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!
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. :)
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 ✨🎉
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
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.❤❤❤
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.
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.
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
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?
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
""" # 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
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 🙇♀🙇♀
You made my day. Thank you so much 🙏🙏🙏❤️❤️
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!!
bhai aap ke jaise koi nhi explain karta hai Aap crysatl clear kar dete ho concept ko thanks bro ❤
Means a lot ❤️
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 ❤️
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. :)
Nice. Thanks for building intuition in both approaches! Makes it enjoyable 🎉
Whenever i stuck at problem , i directly came here 🤩🤩
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!
Appreciate the way you explain each detail with enthusiasm. I really admire you ;)
2nd approach was just superb. And very well explained
Thank you 🙏🙏😇❤️
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. :)
I am so so happy to hear that ❤️❤️❤️
🙏❤️
bhaiya apse bahut kuch sikhn ko milta h pls daily 3,4 vdo daley
Sure. Will definitely try 🙏😇
Ek number bro😊.....floor-->ceil☺
Happy teacher's day bhaiya and thanku for the second apporch ❤❤
It's been our pleasure to learn from u everyday ,happy teachers day 🎉🎉❤❤
The way you explained the space complexity is really good 😇
Glad it helped 😇
Happy teacher's day sir..
After u feel better pls make the question list video sir which I was asking earlier
abhi tk is question ko mai sabse tough smjta tha but ab nai
thanks for your effort bhai
So glad to hear that ❤️🙏😇
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 ✨🎉
Happy Teachers Day, bhaiya... I hope everyone gets a teacher like you.
Best Explanation on the internet💌 Thank you so much.
Happy Teachers' Sir ji
Happy teachers day to our ultimate guru Mike Sir........😊
So beautiful explanation sir. Clear and cut explanation.
N happy teacher's day to u sir🎉🎉🎉.
Hey brother!. Thanks for the video , the second approach was the key take away from the video ..
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;
}
Thanks a lot for sharing ❤️
Best explanation on this problem
Happy Teachers Day, you gave us confidence in DS and made DS easier for us. Thanks a lot 🎉❤
Happy Teacher Day sir, You are such a great teacher.
Making hard problems simple and easy to understand
Nice Explanation !!! Especially for space part really loved it bro.... Happy teacher's Day.
HAPPY TEACHER'S DAY BHAIYA ...LOVE YOUR TRUE & EASY EXPLAINATION ... THANKS++;
Happy Teacher’s Day Sir 😇
Thank you so much for putting so much efforts in your videos to help us. ❤️
Best explanation fr this question on the internet ❣🔥🔥
It means a lot. Thank you so much ❤️❤️
Happy teacher's Day MIK. Hopefully will meet someday
Happy Teachers Day MIK Guruji!
Happy teacher's day sir 🙌
Happy teacher's day ❤
Happy teacher's day sir..
happy teachers day mik bhai... love your content
Happy teachers day guruji
Happy teachers day
Happy teacher's day Mazhar bhaijaan❤...aapko khabar nahi par aap ek video me bohot kuch seekha jate ho❤
Means a lot ❤️🙏😇
Thank you ❤️❤️
Happy teacher's day bhaiya❤❤❤🎉🎉🎉
Happy teacher's day
Happy Teacher's Day Bhaiya. Thank you so much for giving the push though your awesome explanation. ❤
Thank you ❤️🙏😇
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
Definitely. Actually it’s totally debatable. Whatever interviewer agrees for 😇
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.❤❤❤
Happy Teacher day Bhaiya😃😃!! 🙏🙏🙏🙏
Happy Teacher's day🎉 Mik bhai
Happy Teacher's Day Sir❤✨
Happy teacher's day bhaia 🎉😊
Hope you're well.
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.
Hello Manas,
Sure thing. I will add ipad notes link too.
@@codestorywithMIK thanks 😊
10K Soon Bhhaiya And Happy Teacher's Day
Thank you so much 😀
Happy teacher's day bhaiya ❤🙏🏻 aapke bina meri DSA achi hi nahi hoti. all thanks to you🙌🏻
It’s all your hard work 💪🙏❤️
crystal clear sir
😇❤️🙏
Happy teacher's day sir ❤️❤️❤️
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 🎉❤😮
Happy Teachers' Day LEGEND
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.
Wow. Congratulations ❤️💪💪
And thank you for your warm wishes ❤️❤️
@@codestorywithMIK thank you bhaiya 🥰
Happy Teachers Day 🤝
happy teachers day sir.
I am late but Happy Teachers Day sir ❤❤
Happy teacher's day Bhiya ❤️
Happy teachers day sir !!!
Happy Teacher's Day my Hero !
Happy Teachers' Day SIR
happy teacher's day bhaiya
happy teachers day sir
Happy teachers day bhaiya
simillar question :
Clone Graph..
Both have similarities , u have to hash the values before marking down the next connected node.
happy teachers' day bro❤❤
Happy Teacher’s Day ❤
thanks for making videos !!
8:35
Happy Teacher’s Day! 😇
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
Indeed ❤️❤️
❤❤
Happy Teachers’ Day ❤
👌🏼
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?
5/30
legend
Pehle approach mein extra space kaise hua woh create toh ek baar hi kiya hai, chahe result mein use karen ya map mn rakhen
In the first approach, we used map to store the nodes. That’s O(n) extra space we used
but data is crucial part of software development,in second approach we are tampering data,is it correct to do so...
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
Sir face reveal when?
hehe
Waiting for Ted Talk invitation 😉
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
Happy teachers day @ codewithmik
"""
# 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
Happy teacher's day sir❤
❤❤❤
Happy teacher's day bhaiya😊