Number of Operations to Make Network Connected | Leetcode

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

Techdose

Techdose

Күн бұрын

Пікірлер: 49
@raviashwin1157
@raviashwin1157 3 жыл бұрын
After seeing the intution,i was able to code myself,thanku so much❤️
@techdose4u
@techdose4u 3 жыл бұрын
Great
@joydeeprony89
@joydeeprony89 2 жыл бұрын
Great explanation
@adityaojha2701
@adityaojha2701 4 жыл бұрын
Thank you Sir for such a great explanation!!♥
@techdose4u
@techdose4u 4 жыл бұрын
Welcome ☺️
@ekengineer9868
@ekengineer9868 Жыл бұрын
why so clear man
@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 жыл бұрын
👍
@sulthanmogal9692
@sulthanmogal9692 2 жыл бұрын
Than that many checks, we can do this : if (connections.length >= n-1) return totalComponents-1; else return -1;
@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
@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 жыл бұрын
👍🏼
@impatientgaming9868
@impatientgaming9868 Жыл бұрын
Good one
@JohnSmith-uu5gp
@JohnSmith-uu5gp Жыл бұрын
Awesome!
@tejasnakhate
@tejasnakhate 3 жыл бұрын
You can expect a follow-up question here as to print the new edges made to connect network to one component.
@mohdfarman3470
@mohdfarman3470 2 жыл бұрын
Great Explanation❤❤
@prasannapm3220
@prasannapm3220 2 жыл бұрын
Very well logic was built up , thank you
@amanarora8746
@amanarora8746 3 жыл бұрын
here counting the number of components is similar to what we did in leet code P. No 547, counting the provinces?
@nitinkumar5974
@nitinkumar5974 3 жыл бұрын
Awesome & Mine Blowing Explanation THANK YOU so much....brother ♥
@nikhil7129
@nikhil7129 2 жыл бұрын
Best explanation ❤
@sharuk3545
@sharuk3545 4 жыл бұрын
Awesommm explanation bro 🤜 thnk u sooo much
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@srishtisuman2561
@srishtisuman2561 3 жыл бұрын
Loved the explanation
@shivammehta9661
@shivammehta9661 3 жыл бұрын
Very Nice Work
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@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..??
@lokeshsenthilkumar4522
@lokeshsenthilkumar4522 3 жыл бұрын
Hi Sir..can I ask u what tool are you using as a digital board?
@ashishkhoiwal9330
@ashishkhoiwal9330 3 жыл бұрын
at 5:08 did you mean "All extra edges are redundant"?
@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.
@guptashashwat
@guptashashwat 2 жыл бұрын
Read the hints given in LC ques and return number of connected components - 1. Ans.
@ashokk2002
@ashokk2002 3 жыл бұрын
Sir, why to again create an adjacency list ... Can't we use the graph already given in the question
@harishwarreddy9114
@harishwarreddy9114 4 жыл бұрын
It is an easy problem , we want some good questions sir
@techdose4u
@techdose4u 4 жыл бұрын
👍
@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
@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
@davissebastian4799
@davissebastian4799 3 жыл бұрын
vcool
@techdose4u
@techdose4u 3 жыл бұрын
👍🏼
@seyidaniels1350
@seyidaniels1350 4 жыл бұрын
Awesome! First Comment
@techdose4u
@techdose4u 4 жыл бұрын
😀
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
Рет қаралды 97 М.
진짜✅ 아님 가짜❌???
0:21
승비니 Seungbini
Рет қаралды 10 МЛН
Wednesday VS Enid: Who is The Best Mommy? #shorts
0:14
Troom Oki Toki
Рет қаралды 50 МЛН
«Жат бауыр» телехикаясы І 26-бөлім
52:18
Qazaqstan TV / Қазақстан Ұлттық Арнасы
Рет қаралды 434 М.
Kosaraju Algorithm | Strongly connected components in a graph
24:30
AI Is Making You An Illiterate Programmer
27:22
ThePrimeTime
Рет қаралды 279 М.
Network Delay Time | Leetcode #743
19:37
Techdose
Рет қаралды 19 М.
Floyd Warshall algorithm | All pairs shortest path
25:43
Techdose
Рет қаралды 69 М.
one year of studying (it was a mistake)
12:51
Jeffrey Codes
Рет қаралды 317 М.
Detonate the Maximum Bombs - Leetcode 2101 - Python
11:20
NeetCodeIO
Рет қаралды 14 М.
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
진짜✅ 아님 가짜❌???
0:21
승비니 Seungbini
Рет қаралды 10 МЛН