You can expect a follow-up question here as to print the new edges made to connect network to one component.
@amanarora87463 жыл бұрын
here counting the number of components is similar to what we did in leet code P. No 547, counting the provinces?
@joydeeprony892 жыл бұрын
Great explanation
@manishsalvi29014 жыл бұрын
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
@techdose4u4 жыл бұрын
👍
@adityaojha27014 жыл бұрын
Thank you Sir for such a great explanation!!♥
@techdose4u4 жыл бұрын
Welcome ☺️
@ashishkhoiwal93303 жыл бұрын
at 5:08 did you mean "All extra edges are redundant"?
@lokeshsenthilkumar45223 жыл бұрын
Hi Sir..can I ask u what tool are you using as a digital board?
@raviashwin11573 жыл бұрын
After seeing the intution,i was able to code myself,thanku so much❤️
@techdose4u3 жыл бұрын
Great
@impatientgaming9868 Жыл бұрын
Good one
@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..??
@sulthanmogal96922 жыл бұрын
Than that many checks, we can do this : if (connections.length >= n-1) return totalComponents-1; else return -1;
@kp_nagar3 жыл бұрын
great explanation second way is negative case check karte number of component -1 is inf for it.
@techdose4u3 жыл бұрын
👍🏼
@mohdfarman34702 жыл бұрын
Great Explanation❤❤
@sharuk35454 жыл бұрын
Awesommm explanation bro 🤜 thnk u sooo much
@techdose4u4 жыл бұрын
Welcome :)
@ekengineer9868 Жыл бұрын
why so clear man
@ashokk20023 жыл бұрын
Sir, why to again create an adjacency list ... Can't we use the graph already given in the question
@shivammehta96613 жыл бұрын
Very Nice Work
@techdose4u3 жыл бұрын
Thanks
@JohnSmith-uu5gp Жыл бұрын
Awesome!
@prasannapm32202 жыл бұрын
Very well logic was built up , thank you
@nitinkumar59743 жыл бұрын
Awesome & Mine Blowing Explanation THANK YOU so much....brother ♥
@nikhil71292 жыл бұрын
Best explanation ❤
@uditagrawal66033 жыл бұрын
MST cannot be formed of disconnected graph, so here we are trying to form MST like structure for multi component graph? Am i right?
@techdose4u3 жыл бұрын
MST for a single component graph is feasible.
@uditagrawal66033 жыл бұрын
@@techdose4u Yes but here we are dealing with multiple components, so is MST for multiple components is feasible?
@techdose4u3 жыл бұрын
No. In such problems you have to use DSUF in combination to keep track of components.
@nasimahmedbulbul44012 жыл бұрын
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
@srishtisuman25613 жыл бұрын
Loved the explanation
@guptashashwat2 жыл бұрын
Read the hints given in LC ques and return number of connected components - 1. Ans.
@shivamrastogi81463 жыл бұрын
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!
@priyaverma79764 жыл бұрын
Sir it would be helpful if you would do interviewbit questions like you do for leetcode ones
@techdose4u4 жыл бұрын
Actually all interviewbit questions are taken from leetcode. So doing leetcode will cover them both.
@priyaverma79764 жыл бұрын
@@techdose4u okay, thankyou sir
@harishwarreddy91144 жыл бұрын
It is an easy problem , we want some good questions sir
@techdose4u4 жыл бұрын
👍
@simrankureel943 жыл бұрын
It is giving TLE, don't know why ?
@aadishkapoor80883 жыл бұрын
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-nc4rg3 жыл бұрын
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
@yashgaur17162 жыл бұрын
@@aadishkapoor8088 That was really helpful, Thanks brother