Graph was very tough for me but because of your graph concepts playlist today I can solve most of the graph questions easily. Thanks a Lot 😊
@codestorywithMIK Жыл бұрын
You made my day ❤️❤️❤️
@shivanshchauhan52 Жыл бұрын
@@codestorywithMIK Keep going this channel future is very bright !!!
@codestorywithMIK Жыл бұрын
Thank you so much Shivansh ❤️❤️❤️
@kumkumslab58119 ай бұрын
prooved @@shivanshchauhan52
@codestorywithMIK Жыл бұрын
The most detailed and deep dived explanation to this problem you will ever find. Hope you will like it. Please find all the code below : //Approach-1 (DFS) Using vector as map //Approach-2 (DFS) (Using unordered_map) //Approach-3 (BFS) Using vector as map //Approach-4 (BFS) (Using unordered_map) Link : github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Graph/Clone%20Graph.cpp
@souravjoshi2293 Жыл бұрын
The best one bro. I am speechless
@oqant0424 Жыл бұрын
Yaar bhaiya kya padhaya hai aapne ...........dil khush kar diya
@codestorywithMIK Жыл бұрын
Thank you 🙏❤️😇
@JJ-tp2dd Жыл бұрын
Outstanding bhai! You prove every time why you are the undisputed graph king 👑💙💙
@codestorywithMIK Жыл бұрын
Thank you so much JJ
@souravjoshi2293 Жыл бұрын
speechless with this masterpiece
@souravjoshi2293 Жыл бұрын
16:59 ---> That's one of the reasons I come to your channel. I am always sure that I will understand more from your explanations.
@nk-fs8bj9 ай бұрын
Awesome after listing story of 20 minutes write code by own🥳
@r.beditz3674 Жыл бұрын
Never regret watching your explanation videos.❤ Thanks again sir. Here are the Java implementations of your BFS and DFS approaches -: BFS CODE : class Solution { Map map; public Node cloneGraph(Node node) { map = new HashMap(); if(node == null) return null; Node clone = new Node(node.val); map.put(node, clone); Queue q = new ArrayDeque(); q.add(node); while(!q.isEmpty()){ Node curr = q.poll(); Node currClone = map.get(curr); for(Node n : curr.neighbors){ if(!map.containsKey(n)){ Node c = new Node(n.val); map.put(n, c); currClone.neighbors.add(c); q.add(n); } else currClone.neighbors.add(map.get(n)); } } return clone; } } ---------------------------------------------------------------------------------------------------- DFS CODE : class Solution { Map map; public Node cloneGraph(Node node) { map = new HashMap(); if(node == null) return null; Node clone = new Node(node.val); map.put(node, clone); dfs(node, clone); return clone; } private void dfs(Node node, Node clone){ for(Node n : node.neighbors){ if(!map.containsKey(n)){ Node curr = new Node(n.val); map.put(n, curr); clone.neighbors.add(curr); dfs(n, curr); } else clone.neighbors.add(map.get(n)); } } }
@codestorywithMIK Жыл бұрын
Thank you so so much Means a lot to me ❤️
@HarshSharma-zz9di Жыл бұрын
Was able to do today's question without any help, but still here just to like the video. Amazing channel and well structured videos!
@k-CE-OmkarPathak11 ай бұрын
Awesome !! Worth watching 41mins
@codestorywithMIK11 ай бұрын
Thank you so much for watching 😇❤️🙏
@gauravbanerjee28989 ай бұрын
Solved today's GFG POTD after watching this video thank you so much bhaiya ❤❤
@codestorywithMIK9 ай бұрын
Awesome ❤️❤️
@ShivamMishra-fo1wx9 ай бұрын
Great Explanation Makes the question very easy to understand and not only graph u make easy dp also
@iamnoob759319 күн бұрын
Thank you , Amazing explanation.
@level_up.1908 Жыл бұрын
bhai kyu padhate hon itna badhiya 😍
@codestorywithMIK Жыл бұрын
Means a lot ❤️😇
@fshimcds3 ай бұрын
ThankU for best Explanation
@shivkumar-og4ow Жыл бұрын
thanks a lot, bhaiya, nice explanations, are easy to understand.
@souravjoshi2293 Жыл бұрын
The K.I.N.G of Graphs
@JJ-tp2dd Жыл бұрын
so true!
@rahularyan980810 ай бұрын
Really great explanation
@udayshankar-e6v8 ай бұрын
Ye channel bahut aage jane vale h.. bahut bawal samjhata h ye bhai 😍bhai bs bata do kon sa aap use karte ho drawing ke liye .. main bhi install kar lunga..interview me bada proplem hota h diagram vagairh bana ke show karne me
@codestorywithMIK8 ай бұрын
Hi there I use default notes app ❤️🙏 Thank you ☺️
@tutuimam3381 Жыл бұрын
Thanks a lot
@souvickmaity4867 Жыл бұрын
Shi Haai bhai
@gui-codes6 ай бұрын
A message to new comers to this channel - "Graph is Hard until you watch codestorywithMIK"
@aryanvashishtha0001 Жыл бұрын
i love you bro
@vishalgautam-f6v Жыл бұрын
bro u are great at explaining things but u should change ur channel name to a short and simple name, so that we can also recommend ur channel to others as ur current name is slightly difficult to remember
@codestorywithMIK Жыл бұрын
I really appreciate your suggestion ❤️❤️❤️ I will plan to change it to CSM (Code Story With MIK). Right now, my Instagram, linkedIn and , Facebook all have this name and hence might take time to migrate. Thank you so much for your precious suggestions and watching my videos ❤️❤️❤️
@ankitraj41793 ай бұрын
Java Solution /* // Definition for a Node. class Node { public int val; public List neighbors; public Node() { val = 0; neighbors = new ArrayList(); } public Node(int _val) { val = _val; neighbors = new ArrayList(); } public Node(int _val, ArrayList _neighbors) { val = _val; neighbors = _neighbors; } } */ class Solution { public Node cloneGraph(Node node) { if(node == null) return node ; Node clone = new Node(node.val) ; HashMap map = new HashMap() ; map.put(node,clone) ; DFS(node,clone,map) ; return clone ; } public static void DFS(Node org , Node clone , HashMap map){ for(Node neigh : org.neighbors){ if(!map.containsKey(neigh)){ Node tempNode = new Node(neigh.val) ; clone.neighbors.add(tempNode) ; map.put(neigh,tempNode) ; DFS(neigh,tempNode,map) ; } else{ clone.neighbors.add(map.get(neigh)); } } } }
@ankitraj41793 ай бұрын
do like if it helped.
@YashSinghal Жыл бұрын
github link in the description for this problem has a typo its a space instead of underscore so %20 instead of _
@codestorywithMIK Жыл бұрын
Thank you so much Yash. Corrected now. github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Graph/Clone%20Graph.cpp
@jyotishmoydeka6804 Жыл бұрын
Bhaiya it's showing your github page is not available.. and btw thank you for wonderfull explainantion..
@codestorywithMIK Жыл бұрын
Sorry for the typo. Link corrected. github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Graph/Clone%20Graph.cpp
@abhiverma5135 Жыл бұрын
why you wrote map.clear() at the beginning of the function ? whereas we hadn't put any value in the map we just declared it globally? BTW great content ❤✌✌
@codestorywithMIK Жыл бұрын
Hi abhi, Thanks a lot for your appreciation. Actually multiple calls for the function is made. So we don’t want stale entries in the map to be there when a new call is made to the function. But most of the time , even if you don’t clear it, the solution works. But it’s a good practice to do that.
@bhartendupant88599 ай бұрын
❤
@satvrii Жыл бұрын
❤❤❤❤
@codestorywithMIK Жыл бұрын
❤️🙏 Means a lot 😇
@badamadevi9497 Жыл бұрын
Sir java ka code bhi explain krr
@riyakansal3312 Жыл бұрын
Error is coming while opening ur github:(
@codestorywithMIK Жыл бұрын
Link corrected. Can you try again please github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Graph/Clone%20Graph.cpp
@IshanGuleria-l6b5 ай бұрын
iska iterative dfs ka solution h kisi k pass to please send
Thanks Mike for efforts :) Please find below Java Code - class Solution { Map map = new HashMap(); public Node cloneGraph(Node node) { if(node == null){ return null; } Node clone_node = new Node(node.val); map.put(node, clone_node); dfs_traversal(node, clone_node); return clone_node; } void dfs_traversal(Node node, Node clone_node){ for(Node n : node.neighbors){ if(!map.containsKey(n)){ Node clone = new Node(n.val); map.put(n, clone); clone_node.neighbors.add(clone); dfs_traversal(n, clone); } else{ clone_node.neighbors.add(map.get(n)); } } } }
@JJ-tp2dd Жыл бұрын
Why is my comment getting removed?😮
@JJ-tp2dd Жыл бұрын
tried several times to paste the Java code but it is getting removed every time automatically 😥😥
@codestorywithMIK Жыл бұрын
Hi JJ Can you try again. I am also not sure why this is happening
@souravjoshi2293 Жыл бұрын
Was waiting for your java code bro
@JJ-tp2dd Жыл бұрын
@@codestorywithMIK @asimzohr2293 added, hoping it does not get removed
@JJ-tp2dd Жыл бұрын
@@codestorywithMIK it got removed again it seems 😐
@kartikkk4583 Жыл бұрын
Hogya bhai ye, recursion + map, time laga thoda dimag lagane me, @mik bhai aapne competetive programming ki hai kya : unordered_map m; Node* cloneGraph(Node* node) { if(!node)return node; Node* root= new Node(node->val); vector v; m[node]=root; for( auto x : node->neighbors){ if(m.find(x)==m.end()){ v.push_back(cloneGraph(x)); } else{ v.push_back(m[x]); } } root->neighbors=v; return root; }
@codestorywithMIK Жыл бұрын
Hi Kartik, No, i have not done much in Competitive Coding. But would love to try
@abcd768209 ай бұрын
class Solution{ Node cloneGraph(Node node){ Node temp = new Node(node.val); //ab clone krna h recursively iske neighbours ko // saath me ek map bna lete hain taaki koi node bn gya h // to dubara nahi bnega //map ek purana node usk corresponding new node jo //hmne bnaya Map map = new HashMap(); map.put(node,temp); DFS(node,temp,map); return temp; } void DFS(Node node,Node temp,Map map) { //original node k neighbours dhund kr clone krte jaao for(Node neigh : node.neighbors) { // ab do case ya to clone hua hoga ya to nai if(!map.containsKey(neigh)) { Node cloneNeigh = new Node(neigh.val); map.put(neigh,cloneNeigh); temp.neighbors.add(cloneNeigh); DFS(neigh,cloneNeigh,map); } else { temp.neighbors.add(map.get(neigh)); } } } }
@sarthakgudwani4608 Жыл бұрын
Java Implementation class Solution { HashMap mp = new HashMap(); void DFS(Node node, Node clone_node) { for (Node n : node.neighbors) { if (!mp.containsKey(n)) { Node clone = new Node(n.val); mp.put(n, clone); clone_node.neighbors.add(clone); DFS(n, clone); } else { clone_node.neighbors.add(mp.get(n)); } } } Node cloneGraph(Node node) { if (node == null) { return null; } mp.clear(); Node clone_node = new Node(node.val); mp.put(node, clone_node); DFS(node, clone_node); return clone_node; } }