Number of Provinces Leetcode solution | DFS Graph Explained Hindi | Graph in Data structure & Algo
Vložit
- čas přidán 6. 09. 2024
- This is the video under the series of DATA STRUCTURE & ALGORITHM in a GRAPH Playlist. Now we are going to solve the Number of Provinces | Graph series
Join My Telegram channel for more Updates: telegram.me/he...
complete DSA preparation: github.com/Pri...
----------------------------------------------------------------------------------------
Number of Provinces: leetcode.com/p...
code in this video: github.com/Pri...
----------------------------------------------------------------------------------------
*Follow me *
LinkedIn► / iamprince
Facebook► / helloworldofficials
Instagram► / helloworldbyprince
Twitter► / prince_king_
Telegram► telegram.me/he...
----------------------------------------------------------------------------------------
►Our Playlists on:-
► Tree: • Tree Data Structure & ...
► Hashing: • Hashing Data Structure...
► Graph: • Graph Data Structure &...
► Matrix: • Matrix (Multidimension...
► STL: • Standard Template Libr...
► Leetcode: • LeetCode Solutions And...
►Competitive Programming: • Full course in Competi...
►C++ Full Course : • C++ full Course in HINDI
►Algorithms: • L-01 || Prefix Sum Arr...
►Data Structure: • Data Structures with C...
------------------------------------------------------------------------
🌟 Please leave a LIKE ❤️ and SUBSCRIBE for more AMAZING content! 🌟
✨ Tags ✨
leetcode problems
leetcode problems java
leetcode problems python
leetcode problems that got me tired
leetcode problems c++
leetcode problems and solutions python
leetcode problems playlist
leetcode problems and solutions java
leetcode problems in Hindi
leetcode problems javascript
leetcode problems and solutions
leetcode problems of the day
leetcode problems for beginners
leetcode problems easy
leetcode problems js
Introduction to the graph data structure
Graph playlist Hello world
Shortest Path in Unweighted Graph
Print all paths from a given source to a destination
Depth First Search
Graph hello world
Types of graphs in Data structure & algorithms
DFS Graph
playlist Graph Hindi
Number of Provinces leetcode
Number of Provinces solution
question asked in Google
off-campus placement
how to learn to code for beginners
Practice Tree data structure
Unit Area of the largest region of 1's
The graph in a data structure in Hindi
Graph Full playlist for Beginners
algorithms
graph
Number of Provinces
data structure
sorting algorithms
algorithm analysis
Rotting Oranges
gate computer science preparation
programming languages
#Graph #Leetcode #programming
bhaiyya, iske pahle ke saare videos dekhe the maine, to ye video bas open kiya, question ki link me gaya, thodi der socha aur khud se ban gaya dfs se. Thanks guru ji
first i converted the adjacency matrix to adjacency list and then took a counter variable and incremented in the for loop the number of times the dfs is called
your graph series boosted my confidence to a next level
Thanks a ton Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
After watching all the 25 lectures before this...I was able to code it myself...thanks bhaiya💯
Amazing yaar
bhak paagal mat bana copy kiya hoga code
@@idiot8950 tereko nahi ata aisa bol na
@@ani68 bhaag saale noob coder
aaj maine aapka pahala video dekha aur wo dil ko chu gaya
Thanks 😊
Thanks bro for your good lectures , I solve this question on single attempt without watching your solution....
Well done
aapki videos bohot helpful hai. thank you sir
Amazing explanation!! Prince bro you rock!!
Thanks a ton
thank you very much sir for providing these amazing lecture
It's my pleasure
Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
thanks sir now i finally solve problem in my own this playlist is awesome i almost finished it
You are most welcome
class Solution {
public:
void dfs(unordered_map& adj, unordered_set& visited, int node) {
visited.insert(node);
for (int neighbor : adj[node]) {
if (visited.count(neighbor) == 0) {
dfs(adj, visited, neighbor);
}
}
}
int findCircleNum(vector& isConnected) {
unordered_map adj;
unordered_set visited;
for (int i = 0; i < isConnected.size(); i++) {
for (int j = 0; j < isConnected[0].size(); j++) {
if (isConnected[i][j]) {
adj[i].push_back(j);
adj[j].push_back(i); // Add the reverse edge for an undirected graph
}
}
}
int count = 0;
for (int i = 0; i < isConnected.size(); i++) {
if (visited.count(i) == 0) {
dfs(adj, visited, i);
count++;
}
}
return count;
}
};
there is actually no need to create a separate adj vector, you can check the condition of not visited in the first loop itself
I have done it on my own. Thank you so much bhaiya..
so happppyyyy😁❤
Most welcome 😊
Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
@@HelloWorldbyprince sure 😇
One of the best teacher on internet ❤️
Thanks Tanveer
Nice explanation bhaiya... Sare basic concepts ke hi basis pe questions ke logic bn rhe h...thnx...
share please
and I am happy its worked
your motivation is first 2:31 made me solve the problem on my own. Thank you
Yeah ... bass yahi sunnaa tha
Please, if possible then share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
@@HelloWorldbyprince yes ofcourse
bhai done by own
please check it's correct or not
My approach :
void dfs(int node, vector adj[], vector &vis){
vis[node] = true;
for (auto x : adj[node]){
if (vis[x] == false){
dfs(x, adj, vis);
}
}
}
int findCircleNum(vector& isConnected) {
int n = isConnected.size();
vector adj[n+1];
for (int i=0 ; i
thanks Prince bhai , u gave me confidence to solve the graph questions
best sir ji
Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
Great Video...Thanks..Please keep on making such series
Thanks, will do!
@@HelloWorldbyprince A series on Greedy and Bit Manipulation will be very helpful...Greedy playlist is not there in youtube.
Thanks bhyya awesome videos
bhai yeh number of islands wale question ki tarah dikh raha, usse kaise alag hai?
I think we don't need to create the adjacency list.
we can do this without it.
thank you bhaiya
Keep growing and learning
Nice Explanation! can you please also explain complexity of this solution?
same as DFS one
nice bhaiya
Thanks a ton buddy
Great vid!
Thanks please share bro Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
//Code by DFS
//User function Template for Java
class Solution {
static int numProvinces(ArrayList adj, int V) {
ArrayList []arr = new ArrayList[V];
for(int i=0;i
Ranchi 🙋🏻
Nice bro
sir aap ranchi se ho kya
even i live in ranchi pls tell me where u live i want to meet u big fan
sure we will meet in ranchi
26/32 done
amazing
count the number of disconnected components
yesss
Hi bhaiyaa i make youtube thumbnails and i also want to for you so are you intrested ?
connect over me instagram @helloworldbyprince
agar college me share karenge toh sab padh lenge toh ham piche ho jaaenge
Hahaha
saari information khud hi lenge
nhiiiiiiiiii,
share v kar dena