Number of Provinces Leetcode solution | DFS Graph Explained Hindi | Graph in Data structure & Algo

Sdílet
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

Komentáře • 68

  • @cs_in_10_minutes
    @cs_in_10_minutes Před 16 dny

    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

  • @pritishpattnaik4674
    @pritishpattnaik4674 Před 2 lety +5

    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

  • @oqant0424
    @oqant0424 Před 2 lety +3

    your graph series boosted my confidence to a next level

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před rokem

      Thanks a ton Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀

  • @ani68
    @ani68 Před 2 lety +5

    After watching all the 25 lectures before this...I was able to code it myself...thanks bhaiya💯

  • @ashishverma1382
    @ashishverma1382 Před 2 lety +2

    aaj maine aapka pahala video dekha aur wo dil ko chu gaya

  • @rahulgautam6387
    @rahulgautam6387 Před 2 lety +2

    Thanks bro for your good lectures , I solve this question on single attempt without watching your solution....

  • @anushka23429
    @anushka23429 Před měsícem

    aapki videos bohot helpful hai. thank you sir

  • @kuldeepchouhan8467
    @kuldeepchouhan8467 Před 7 měsíci

    Amazing explanation!! Prince bro you rock!!

  • @CodeLearnIit
    @CodeLearnIit Před 2 lety +1

    thank you very much sir for providing these amazing lecture

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 2 lety

      It's my pleasure
      Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀

  • @shailesh2064
    @shailesh2064 Před rokem

    thanks sir now i finally solve problem in my own this playlist is awesome i almost finished it

  • @user-uc2pl1or2x
    @user-uc2pl1or2x Před rokem

    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;
    }
    };

  • @paper-studio
    @paper-studio Před rokem

    there is actually no need to create a separate adj vector, you can check the condition of not visited in the first loop itself

  • @anonymous090
    @anonymous090 Před 2 lety +1

    I have done it on my own. Thank you so much bhaiya..
    so happppyyyy😁❤

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 2 lety +2

      Most welcome 😊
      Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀

    • @anonymous090
      @anonymous090 Před 2 lety

      @@HelloWorldbyprince sure 😇

  • @tanveeralam3971
    @tanveeralam3971 Před rokem

    One of the best teacher on internet ❤️

  • @sus_tha_coder
    @sus_tha_coder Před 2 lety

    Nice explanation bhaiya... Sare basic concepts ke hi basis pe questions ke logic bn rhe h...thnx...

  • @programmingrush
    @programmingrush Před 2 lety

    your motivation is first 2:31 made me solve the problem on my own. Thank you

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 2 lety

      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 😀

    • @programmingrush
      @programmingrush Před 2 lety

      @@HelloWorldbyprince yes ofcourse

  • @pritishpattnaik4674
    @pritishpattnaik4674 Před 2 lety +1

    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

  • @pritishpattnaik4674
    @pritishpattnaik4674 Před 2 lety

    thanks Prince bhai , u gave me confidence to solve the graph questions

  • @amankumar-ig2fe
    @amankumar-ig2fe Před 10 měsíci

    best sir ji

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 9 měsíci

      Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀

  • @realAB459
    @realAB459 Před 2 lety

    Great Video...Thanks..Please keep on making such series

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 2 lety

      Thanks, will do!

    • @realAB459
      @realAB459 Před 2 lety

      @@HelloWorldbyprince A series on Greedy and Bit Manipulation will be very helpful...Greedy playlist is not there in youtube.

  • @shadaabkhan4608
    @shadaabkhan4608 Před rokem

    Thanks bhyya awesome videos

  • @abhineetsingh6720
    @abhineetsingh6720 Před 2 lety

    bhai yeh number of islands wale question ki tarah dikh raha, usse kaise alag hai?

  • @SaurabhSingh-ch6nc
    @SaurabhSingh-ch6nc Před 2 lety +1

    I think we don't need to create the adjacency list.
    we can do this without it.

  • @akankshagupta2312
    @akankshagupta2312 Před 2 lety

    thank you bhaiya

  • @indianview6103
    @indianview6103 Před 2 lety

    Nice Explanation! can you please also explain complexity of this solution?

  • @MakeuPerfect
    @MakeuPerfect Před 2 lety

    nice bhaiya

  • @sumitbaghel9987
    @sumitbaghel9987 Před 2 lety

    Great vid!

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před rokem

      Thanks please share bro Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀

  • @pranavkorhale5089
    @pranavkorhale5089 Před rokem

    //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

  • @pranaymishra5456
    @pranaymishra5456 Před 7 měsíci

    Ranchi 🙋🏻

  • @anshumantripathi5747
    @anshumantripathi5747 Před 6 měsíci

    sir aap ranchi se ho kya

  • @shadabkalim9102
    @shadabkalim9102 Před rokem

    even i live in ranchi pls tell me where u live i want to meet u big fan

  • @oqant0424
    @oqant0424 Před 2 lety

    26/32 done

  • @jayeshyadav07
    @jayeshyadav07 Před 2 lety

    count the number of disconnected components

  • @theedit9028
    @theedit9028 Před 2 lety

    Hi bhaiyaa i make youtube thumbnails and i also want to for you so are you intrested ?

  • @idiot8950
    @idiot8950 Před rokem

    agar college me share karenge toh sab padh lenge toh ham piche ho jaaenge

  • @idiot8950
    @idiot8950 Před rokem

    saari information khud hi lenge