Remembering that I used to see your videos before getting placed is another level of nostalgia 😂
@techdose4u4 жыл бұрын
Bro I also remember you used to actively interact and ask so many questions about placement. Now I am happy that you got placed :)
@akshatjain68544 жыл бұрын
@@techdose4u Thank you so much brother, My resume was shortlisted because of the coding profile that I made on leetcode.And It was because of you I was able to solve 210 problems on leetcode.Worked harder for those 3 months , watched your tutorial everyday and recommended the same to all my friends. It helped a lot in my interviews To anyone who is reading this and preparing for SDE role, this channel is the best one and in fact far better than all the paid courses.He is doing a social work by uploading these amazing tutorials so guys support him as much as you can!
@agileprogramming74634 жыл бұрын
@@akshatjain6854 Cannot agree more. Btw can you please tell how you got shortlisted based on your Leetcode profile ?
@akshatjain68544 жыл бұрын
@@agileprogramming7463 I had put my leetcode profile link in resume.I think that helped because before putting this I wasn't getting shortlisted for interviews
@spetsnaz_24 жыл бұрын
@@akshatjain6854 Which company did you get cracked bro ?
@AstonishingStudios2 жыл бұрын
In the cloneGraph function, you could remove all lines below the creation of "copy", excluding the "return copy;" line, and precede the "return copy;" with "DFS(node, copy, visited);" so you don't have to write a for loop twice.
@aryamarda16433 жыл бұрын
You teach at a very different level, clear to understand, explained deeply.and code easy to understand
@techdose4u3 жыл бұрын
Thanks
@bostonlights27494 жыл бұрын
Commenting for the YT algorithm so that this channel gets famous. Awesome stuff bro
@techdose4u4 жыл бұрын
Thanks :)
@abhishekjaiswal64923 жыл бұрын
i think time complexity should be O(V+E) same as dfs because no extra loop or recursion is there .
@shresthmishra93294 жыл бұрын
When I click on any of your video, I know for sure that I won't forget the concept. Thank you for such great videos and clear/precised explanations. Miss your frequent videos though.
@techdose4u4 жыл бұрын
Yep....I am at home now. I will start upload from tommorow :) Stay tuned!
@muskangupta58733 жыл бұрын
After Watching it twice I got the logic thank you very much bro!!
@techdose4u3 жыл бұрын
Great
@ayushanand10322 жыл бұрын
I wonder.... why I always get confused by the way you explain any problem!!!!😕😕
@sandeepsaluru65874 жыл бұрын
Solution in python using dfs first to make adjacency list, then copying it using new nodes. I think this will be useful. Leetcode accepted submission in python from collections import defaultdict # Definition for a Node. class Node: def __init__(self, val = 0, neighbors = None): self.val = val self.neighbors = neighbors if neighbors is not None else [] class Solution: def cloneGraph(self, node: 'Node') -> 'Node': adj = defaultdict(list) visited =[False]*101 queue = [] if node is None: print(node) return if len(node.neighbors) == 0: return Node(node.val) self.dfs(node, visited, adj) ans = [] for i in list(adj.keys()): ans.append(adj[i]) new_nodes = defaultdict(list) for key in list(adj.keys()): new_nodes[key].append(Node(val = key)) for key in list(adj.keys()): nei = adj[key] if len(adj[key]) == 0: continue else: for nei in adj[key]: new_nodes[key][0].neighbors.append(new_nodes[nei][0]) return new_nodes[1][0] def dfs(self, node, visited, adj): visited[node.val] = True if len(node.neighbors) == 0: return for neighbour in node.neighbors: if visited[neighbour.val] == False: adj[node.val].append(neighbour.val) self.dfs(neighbour, visited, adj) else: adj[node.val].append(neighbour.val) return
@arnavkarforma30154 жыл бұрын
Just in case if anyone is looking for the same dfs based solution in java class Solution { public HashMap map = new HashMap(); public Node cloneGraph(Node node) { return clone(node); } public Node clone(Node node) { if (node == null) return null; if (map.containsKey(node.val)) return map.get(node.val); Node newNode = new Node(node.val, new ArrayList()); map.put(newNode.val, newNode); for (Node neighbor : node.neighbors) newNode.neighbors.add(clone(neighbor)); return newNode; } }
@techdose4u4 жыл бұрын
👍
@jaydave25004 жыл бұрын
The first for loop in main will not be required we can directly call dfs cause the graph is connected....
@techdose4u4 жыл бұрын
Yea. Only if it's connected.
@damanpreetsingh65304 жыл бұрын
Best Explaination
@techdose4u4 жыл бұрын
Thanks :)
@shobhitkumar68204 жыл бұрын
why can' t we use visited[node->val] for the visited array??
@rohitsoni96113 жыл бұрын
Nice Explanation Simple Java Code: class Solution { Node[] visited = new Node[101];//keep a track of visited nodes public Node cloneGraph(Node node) { return dfs(node); } public Node dfs(Node root){ if(root==null) return null; if(visited[root.val]==null) { Node copy = new Node(root.val); visited[root.val] = copy; for(int i=0;i
@techdose4u3 жыл бұрын
👍🏼
@nikhilchandna48513 жыл бұрын
Shouldn't the time complexity be O(V+E) instead of O(VE) , since we are keeping track of visited nodes??
@voldemort5763 жыл бұрын
Yes i also think so! but when graph is complete connected E = V*(V-1)
@rohankumarshah56792 жыл бұрын
very wonderful tutorial, but you code is giving run time error in interview bit while submitting but it works fine while testing
@harshtyagi7002 жыл бұрын
Great Explaination
@techdose4u2 жыл бұрын
Thanks 😊
@bhaskersaiteja95318 ай бұрын
If possible explain the time complexity again please
@garimaagrawal59374 жыл бұрын
Sir will you make videos on leetcode july challenge also? Your june challenge series really helped a lot 😊
@techdose4u4 жыл бұрын
I will make only selected questions
@paragroy535910 ай бұрын
Great content, Keep on making such videos.
@mahipalsingh-yo4jt4 жыл бұрын
very good explanation......... Thanks ...
@techdose4u4 жыл бұрын
Welcome :)
@caminante42223 жыл бұрын
you have the best explanations
@techdose4u3 жыл бұрын
Thanks
@rahulsrivastava97102 жыл бұрын
why can't we compare node->val as simple visited array ?
@setYourHandleHttp4044 жыл бұрын
Thanks for your excellent explanations! BFS and HashMap weren't easier?
@kunalagrawal20502 жыл бұрын
what was the time complexity
@kunalsoni76814 жыл бұрын
Sir Really your explanation style is brilliant 😊☺️.. you always explain brute force approach firstly then you will go to optimise approach so that everyone can understand deeply 😇.. thank you sir..
@lipishah4744 жыл бұрын
Thank you so much for such a nice explanation sir ☺️
@techdose4u4 жыл бұрын
Welcome :)
@spetsnaz_24 жыл бұрын
[PYTHON SOLUTION] 1 liner I found a very simple way to solve this question in just 1 line using Python 😂 return deepcopy(node)
@techdose4u4 жыл бұрын
Can't explain like this in interview 😅
@spetsnaz_24 жыл бұрын
@@techdose4u true, but these kind of solutions are just for fun. Otherwise the interviewer will kick me 😂
@manvisingh3074 жыл бұрын
Awesome explanation ! which software did you use for making these videos?
@VenkatIyer3 жыл бұрын
Amazing explanation. Just a quick question, on the code where is the backtracking happening? Is it because the (node->neighbors) vector is already flooded with the newly made nodes?
@agileprogramming74634 жыл бұрын
TECH DOSE is back!!!!
@techdose4u4 жыл бұрын
Yep 😁
@RakeshKumar-he6ek3 жыл бұрын
Great!
@Arjun693 жыл бұрын
LEGEND.
@techdose4u3 жыл бұрын
😄
@mystryb3453 жыл бұрын
Bro posssible plz cover median of Two sorted array
@techdose4u3 жыл бұрын
I will try when I start that topic
@saikumartadi84944 жыл бұрын
Sir. Isn't the time complexity equal t O(E+V) which for a complete graph is O(E) .we are basically using DFS here right? and the time complexity should be equal to that if DFS right?
@alokesh9853 жыл бұрын
Yep, it is linear time
@SiddheshKukade Жыл бұрын
thanks
@crimsoncad32304 жыл бұрын
Bro can you make a Telegram discussion group? It'll be helpful. And if you are busy then someone else from this group can help in solving doubts.
@techdose4u4 жыл бұрын
Soon bro soon
@techdose4u4 жыл бұрын
Made the channel and group
@ArpitDhamija4 жыл бұрын
@@techdose4u link?
@ellis-pr7hh Жыл бұрын
YOU DONT NEED TO ITERATE THROUGH THE FIRST NODE NEIGBORS CAUSE THERE ARE NOT DISCONNECTED COMPONENTS..CHECK THE BELOW CODE void dfs(Node* curr, Node* node, vector &vis){ vis[node->val] = node; for(auto i: curr->neighbors){ if(vis[i->val] == NULL){ Node* newnode = new Node(i->val); (node->neighbors).push_back(newnode); dfs(i, newnode, vis); } else{ (node->neighbors).push_back(vis[i->val]); } } } Node* cloneGraph(Node* node) { if(node == NULL) return NULL; vector vis(1000, NULL); Node* newnode = new Node(node->val); dfs(node, newnode, vis); return newnode; }
""" PYTHON CODE # Definition for a Node. class Node: def __init__(self, val = 0, neighbors = None): self.val = val self.neighbors = neighbors if neighbors is not None else [] """ class Solution: def cloneGraph(self, node: 'Node') -> 'Node': visited = [None]*1000 def connect(node): if node==None: return None if visited[node.val-1]!=None: return visited[node.val-1]=Node(node.val,None) for nbr in node.neighbors: connect(nbr) newNbrs = [] for nbr in node.neighbors: newNbrs.append(visited[nbr.val-1]) visited[node.val-1].neighbors = newNbrs connect(node) return (visited[0])
@alexsparrow86144 жыл бұрын
OMG ........ Where is today leet code solution ?
@techdose4u4 жыл бұрын
It was so simple that I dint upload it. Please follow my community post announcement.