Diameter Of Undirected Graph | Tree Diameter | Leetcode 1245 | Graph Concepts & Qns - 44 | MIK

Поділитися
Вставка
  • Опубліковано 27 гру 2024

КОМЕНТАРІ • 47

  • @NikhilYadav-i2f
    @NikhilYadav-i2f 3 дні тому +11

    Feels so honoured that He is my college alumni, absolute goated stuff Bhaiya🦾

    • @codestorywithMIK
      @codestorywithMIK  3 дні тому +2

      This means a lot ❤️🙏

    • @NikhilYadav-i2f
      @NikhilYadav-i2f 3 дні тому

      @@codestorywithMIK Can we connect by any means, Bhaiya? Need some advice regarding tech stuffs and hiring, this year has been drastic for us with regards to internship and placement.

  • @codestorywithMIK
    @codestorywithMIK  3 дні тому +16

    NOTE - The diameter of a tree or graph represents the longest path between any two nodes, and this path does NOT contain any REPEATED edges or nodes.
    Today's POTD Link - ua-cam.com/video/uz_WISpySFs/v-deo.html

    • @ShivamSharma-vf4uf
      @ShivamSharma-vf4uf 3 дні тому

      SIR PLEASE SOLVE 21 DEC AND 22 DEC Problem of the day as you skipped these problems on that day

  • @PiyushMehta-km3cb
    @PiyushMehta-km3cb 2 дні тому +1

    4 minutes into the video, just saw the fact about the diameter and solved it, bro you are goated, wonder why no one ever told about that diameter fact, it blowed my mind!! thanks.

  • @sumitgupta310
    @sumitgupta310 3 дні тому +5

    Leetcode : 3203 (using video Explaination)
    sol :
    class Solution {
    public:
    pair bfsTofindFarthestNode(int s, int v, unordered_map& adj) {
    vector vis(v, false);
    queue q;
    q.push(s);
    vis[s] = true; // Mark starting node as visited
    int level = 0, farthestNode = s;
    while (!q.empty()) {
    int n = q.size();
    for (int i = 0; i < n; i++) {
    int node = q.front();
    q.pop();
    farthestNode = node;
    for (auto it : adj[node]) {
    if (!vis[it]) {
    vis[it] = true; // Mark neighbor as visited before enqueueing
    q.push(it);
    }
    }
    }
    if (!q.empty()) level++;
    }
    return {farthestNode, level};
    }
    int treeDiameter(vector& edges) {
    int v = edges.size() + 1; // Number of nodes
    unordered_map adj;
    for (const auto& edge : edges) {
    int u = edge[0], v = edge[1];
    adj[u].push_back(v);
    adj[v].push_back(u);
    }
    auto oneEndNode = bfsTofindFarthestNode(0, v, adj);
    auto otherEndNode = bfsTofindFarthestNode(oneEndNode.first, v, adj);
    return otherEndNode.second; // Diameter of the tree
    }
    int minimumDiameterAfterMerge(vector& edges1, vector& edges2) {
    int dia1 = treeDiameter(edges1);
    int dia2 = treeDiameter(edges2);
    int combinedDia = ceil(dia1 / 2.0) + ceil(dia2 / 2.0) + 1;
    return max({dia1, dia2, combinedDia});
    }
    };

  • @aws_handles
    @aws_handles 3 дні тому +2

    Man you are a legend and so hard working. Thank you for clearing the concepts. Now I can understand the POTD

  • @gui-codes
    @gui-codes 3 дні тому +2

    Done and crystal clear. These concepts I was not even taught in a paid course I took years ago. I wish I had found you earlier.
    Waiting for today's POTD now.

  • @SiddheshPardeshi-mp9cr
    @SiddheshPardeshi-mp9cr 3 дні тому +1

    Amazing explanation, Keep the good work

  • @Abraham33286
    @Abraham33286 3 дні тому

    Your explanation is unbeatable.

  • @Coder_Buzz07
    @Coder_Buzz07 3 дні тому +5

    First view😍❤

  • @sumitkumarmahto5081
    @sumitkumarmahto5081 2 дні тому +1

    One small correction here:
    at 7:06, you say : d(u, A) d(u, B)
    But you could also argue that if we switch the nodes A and B in the above equation and the condition above remains true.
    Maybe the right wording of the statement should be:
    If we consider that B is always the farthest node from u, then the following condition is always True:
    d(u, A)

  • @k-CE-OmkarPathak
    @k-CE-OmkarPathak 3 дні тому +1

    Great concepts

  • @I_Love_You_Mansi_Forever
    @I_Love_You_Mansi_Forever 3 дні тому

    mik sir you are so underrated!!

  • @vaibhavyadav3301
    @vaibhavyadav3301 3 дні тому +2

    Bro your whole content is aroud dsa and leetcode, you should take the premium again 😅

  • @gui-codes
    @gui-codes 3 дні тому +1

    Wow. Thanks a lot MIK. Was waiting for this one.

  • @metirajendar6396
    @metirajendar6396 3 дні тому +1

    What if the node 5 has two child nodes(say 10 and 11) in the dry run? Do we get multiple options for diameters? How does this effect the diameter paths(having multiple paths with diameter k)?

  • @soumyasatish7941
    @soumyasatish7941 2 дні тому

    Hello @codestorywithMIK, at 7:15 in the video, d(u, A) can be greater than d(u, B) right?

    • @codestorywithMIK
      @codestorywithMIK  2 дні тому

      Yes yes definitely. It can be. I just took a case . There can be many cases

    • @soumyasatish7941
      @soumyasatish7941 2 дні тому

      @@codestorywithMIK Okay, so we needed one case to prove by contradiction. Thanks for the prompt reply

  • @varunaggarwal7126
    @varunaggarwal7126 3 дні тому +2

    I made silly mistakes during oa rounds due to stress, later I was able to solve 😭😭

  • @abhinay.k
    @abhinay.k 3 дні тому +2

    20:14

  • @amardeep7714
    @amardeep7714 3 дні тому

    MIK , plz 1 vdeo on Bridge of graph....i knw ki dfs s hoga ..time stamp discovery and finish time ka concept h but still achhe s clear nai hua h...so plz try to bring that too..
    Also i am placed in campus in PSU with 21 ctc. Thankyou so much for everything .

  • @ashutoshchouhan9610
    @ashutoshchouhan9610 3 дні тому +1

    14:24 🔔 vo yaha kisa lye karaga 😂😂🤣

  • @ShivamSharma-vf4uf
    @ShivamSharma-vf4uf 3 дні тому +1

    SIR PLEASE SOLVE 21 DEC AND 22 DEC Problem of the day as you skipped these problems on that day @codestorywithMIK

  • @anshuman5554
    @anshuman5554 3 дні тому +2

    Sir, expedia group USA ke liye refer kr skte ho kya? i am doing my masters here

  • @abhinay.k
    @abhinay.k 3 дні тому +1

    Thanks sir

  • @RishabhChatterjee-fg2gz
    @RishabhChatterjee-fg2gz 3 дні тому +1

    Bhaiya mathematical proof wala ek baar firse samjha do,
    Aur Bhaiya d(u,a) > d(u,b) ho sakta hai aap jo diagram liye uske basis pe aagar mein u ko b se 1 distance pe rakhu, ye wala thik se samajh nhi aaya, mathematical wala ek baar aur Bhaiya please

  • @varunpalsingh3822
    @varunpalsingh3822 3 дні тому

    MIK ek roadmap bana sakte ho ? How to get good tech job in 2025 I sometimes got distract from my path ki what how and where to do

  • @yogendrakesharwani3650
    @yogendrakesharwani3650 3 дні тому

    I am not able to search for leetcode POTD section. Where is that section ?

    • @codestorywithMIK
      @codestorywithMIK  3 дні тому

      ua-cam.com/video/uz_WISpySFs/v-deo.htmlsi=btJ8DB81bcdJITlu

    • @pradeepgpt
      @pradeepgpt 3 дні тому

      Its daily challenge problems, You can find in the right side of the problem section.(Looks like calendar)

  • @aadityaraj2397
    @aadityaraj2397 3 дні тому

    ye question CSES sheet me bhi hai

  • @anshkapooriitb6458
    @anshkapooriitb6458 3 дні тому +2

    2940. Find Building Where Alice and Bob Can Meet
    solution video please

  • @SurajGupta-gc9tz
    @SurajGupta-gc9tz День тому

    d(A,B) < d(U,V) + d(U,B) 13:01 yeh toh ho hi sakta hai koi ek path hamesha diameter se chota hoga ya toh do paths hai u se v aur u se B
    correct me if i am worng

    • @codestorywithMIK
      @codestorywithMIK  День тому

      If you notice d(U,V) + d(U,B) contains one duplicate path as well. We need to exclude any path counting more than once. Diameter is the longest path between any two nodes and each path is counted only once.

  • @HeetVichhivora
    @HeetVichhivora 3 дні тому

    Mik bhaiya perso ka video please

  • @sarangkale6761
    @sarangkale6761 3 дні тому +4

    Sir Aaj POTD nhi solve karenge?

    • @codestorywithMIK
      @codestorywithMIK  3 дні тому +13

      Definitely it will come. But before solving today's POTD, this video is going to be very important. Do watch this one because we will directly use the code of this video to today's POTD.

    • @sarangkale6761
      @sarangkale6761 3 дні тому

      @codestorywithMIK yess sir

  • @meetdobariya8777
    @meetdobariya8777 3 дні тому

    Last two days

  • @Ramgangakumar
    @Ramgangakumar 2 дні тому +1

    tattoo banva lo 😂😂 3 points ko