Number of Operations to Make Network Connected | Leetcode

  Рет қаралды 17,329

Techdose

Techdose

Күн бұрын

Пікірлер
@tejasnakhate
@tejasnakhate 3 жыл бұрын
You can expect a follow-up question here as to print the new edges made to connect network to one component.
@amanarora8746
@amanarora8746 3 жыл бұрын
here counting the number of components is similar to what we did in leet code P. No 547, counting the provinces?
@joydeeprony89
@joydeeprony89 2 жыл бұрын
Great explanation
@manishsalvi2901
@manishsalvi2901 4 жыл бұрын
I did the same thing. But I ignored counting number of redundant edges because as it has number of edges greater than n-1 then it will definitely form a connected graph. here is what I did class Solution { public: void dfs(int i,vector &visited,vector &connections) { visited[i]=true; for(int u:connections[i]) { if(!visited[u]) dfs(u,visited,connections); } } int makeConnected(int n, vector& connections) { vector adj(n+1); for(int i=0;i
@techdose4u
@techdose4u 4 жыл бұрын
👍
@adityaojha2701
@adityaojha2701 4 жыл бұрын
Thank you Sir for such a great explanation!!♥
@techdose4u
@techdose4u 4 жыл бұрын
Welcome ☺️
@ashishkhoiwal9330
@ashishkhoiwal9330 3 жыл бұрын
at 5:08 did you mean "All extra edges are redundant"?
@lokeshsenthilkumar4522
@lokeshsenthilkumar4522 3 жыл бұрын
Hi Sir..can I ask u what tool are you using as a digital board?
@raviashwin1157
@raviashwin1157 3 жыл бұрын
After seeing the intution,i was able to code myself,thanku so much❤️
@techdose4u
@techdose4u 3 жыл бұрын
Great
@impatientgaming9868
@impatientgaming9868 Жыл бұрын
Good one
@mohitmanuja7239
@mohitmanuja7239 Жыл бұрын
Hi, As we already checked that min number of edges required are n-1, so if there are n-1 edges present then we can simply return components-1 as result rather than finding redundant. Is my understanding correct, if not can you explain..??
@sulthanmogal9692
@sulthanmogal9692 2 жыл бұрын
Than that many checks, we can do this : if (connections.length >= n-1) return totalComponents-1; else return -1;
@kp_nagar
@kp_nagar 3 жыл бұрын
great explanation second way is negative case check karte number of component -1 is inf for it.
@techdose4u
@techdose4u 3 жыл бұрын
👍🏼
@mohdfarman3470
@mohdfarman3470 2 жыл бұрын
Great Explanation❤❤
@sharuk3545
@sharuk3545 4 жыл бұрын
Awesommm explanation bro 🤜 thnk u sooo much
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@ekengineer9868
@ekengineer9868 Жыл бұрын
why so clear man
@ashokk2002
@ashokk2002 3 жыл бұрын
Sir, why to again create an adjacency list ... Can't we use the graph already given in the question
@shivammehta9661
@shivammehta9661 3 жыл бұрын
Very Nice Work
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@JohnSmith-uu5gp
@JohnSmith-uu5gp Жыл бұрын
Awesome!
@prasannapm3220
@prasannapm3220 2 жыл бұрын
Very well logic was built up , thank you
@nitinkumar5974
@nitinkumar5974 3 жыл бұрын
Awesome & Mine Blowing Explanation THANK YOU so much....brother ♥
@nikhil7129
@nikhil7129 2 жыл бұрын
Best explanation ❤
@uditagrawal6603
@uditagrawal6603 3 жыл бұрын
MST cannot be formed of disconnected graph, so here we are trying to form MST like structure for multi component graph? Am i right?
@techdose4u
@techdose4u 3 жыл бұрын
MST for a single component graph is feasible.
@uditagrawal6603
@uditagrawal6603 3 жыл бұрын
@@techdose4u Yes but here we are dealing with multiple components, so is MST for multiple components is feasible?
@techdose4u
@techdose4u 3 жыл бұрын
No. In such problems you have to use DSUF in combination to keep track of components.
@nasimahmedbulbul4401
@nasimahmedbulbul4401 2 жыл бұрын
Redundant part can be ignored as if edges>=n-1 there is an solution for sure. Then we can just return components-1; Solution: class Solution { public: void DFS(unordered_map&adj, int curr, vector&visited){ visited[curr]=true; for(auto it: adj[curr]){ if(visited[it]==false){ DFS(adj,it,visited); } } } int makeConnected(int n, vector& connections) { vectorvisited(n,false); unordered_mapadj; int edges = connections.size(); if(edges
@srishtisuman2561
@srishtisuman2561 3 жыл бұрын
Loved the explanation
@guptashashwat
@guptashashwat 2 жыл бұрын
Read the hints given in LC ques and return number of connected components - 1. Ans.
@shivamrastogi8146
@shivamrastogi8146 3 жыл бұрын
redundantEdges (r) = Total Edges (E) - ( (n-1) - (c-1) ) for answer to exist: r >= c-1 Put value of r from first eqn into second eqn and solve. You will get E >= (n-1) which we have already checked earlier. So there is NO NEED to check if r>=c-1 or not. If E>=n-1 some answer will always exist!
@priyaverma7976
@priyaverma7976 4 жыл бұрын
Sir it would be helpful if you would do interviewbit questions like you do for leetcode ones
@techdose4u
@techdose4u 4 жыл бұрын
Actually all interviewbit questions are taken from leetcode. So doing leetcode will cover them both.
@priyaverma7976
@priyaverma7976 4 жыл бұрын
@@techdose4u okay, thankyou sir
@harishwarreddy9114
@harishwarreddy9114 4 жыл бұрын
It is an easy problem , we want some good questions sir
@techdose4u
@techdose4u 4 жыл бұрын
👍
@simrankureel94
@simrankureel94 3 жыл бұрын
It is giving TLE, don't know why ?
@aadishkapoor8088
@aadishkapoor8088 3 жыл бұрын
use vectoradj[ n] instead of using map for storing adjacency list. Just write this in place of unordered_map adj and it should work fine
@Arya-nc4rg
@Arya-nc4rg 3 жыл бұрын
Hey guys I want some companion in coding so that if we have doubts regarding any questions so we can help each other. So are you interested to join us
@yashgaur1716
@yashgaur1716 2 жыл бұрын
@@aadishkapoor8088 That was really helpful, Thanks brother
@seyidaniels1350
@seyidaniels1350 4 жыл бұрын
Awesome! First Comment
@techdose4u
@techdose4u 4 жыл бұрын
😀
@davissebastian4799
@davissebastian4799 3 жыл бұрын
vcool
@techdose4u
@techdose4u 3 жыл бұрын
👍🏼
Prims vs Dijkstra algorithm | MST vs SSSP
15:08
Techdose
Рет қаралды 14 М.
G-49. Number of Operations to Make Network Connected - DSU
14:48
take U forward
Рет қаралды 95 М.
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 30 МЛН
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 158 МЛН
Kosaraju Algorithm | Strongly connected components in a graph
24:30
Network Delay Time | Leetcode #743
19:37
Techdose
Рет қаралды 19 М.
Every Minute One Person Is Eliminated
34:46
MrBeast
Рет қаралды 9 МЛН
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 689 М.