Maximum Total Importance of Roads | Thought Process | Leetcode 2285 | codestorywithMIK

Sdílet
Vložit
  • čas přidán 26. 06. 2024
  • Whatsapp Community Link : www.whatsapp.com/channel/0029...
    This is the 50th Video of our Playlist "Graphs : Popular Interview Problems" by codestorywithMIK
    In this video we will try to solve a good observation practice problem : Maximum Total Importance of Roads | Thought Process | Leetcode 2285 | codestorywithMIK
    I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
    We will do live coding after explanation and see if we are able to pass all the test cases.
    Also, please note that my Github solution link below contains both C++ as well as JAVA code.
    Problem Name : Maximum Total Importance of Roads | Thought Process | Leetcode 2285 | codestorywithMIK
    Company Tags : ADOBE
    My solutions on Github(C++ & JAVA) : github.com/MAZHARMIK/Intervie...
    Leetcode Link : leetcode.com/problems/maximum...
    My DP Concepts Playlist : • Roadmap for DP | How t...
    My Graph Concepts Playlist : • Graph Concepts & Qns -...
    My Recursion Concepts Playlist : • Introduction | Recursi...
    My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
    Instagram : / codestorywithmik
    Facebook : / 100090524295846
    Twitter : / cswithmik
    Subscribe to my channel : / @codestorywithmik
    ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
    ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
    ╠╗║╚╝║║╠╗║╚╣║║║║║═╣
    ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
    Summary :
    The approach to solving the problem of calculating the maximum importance of nodes in a graph involves the following steps:
    Degree Calculation:
    Initialize an array to store the degree (number of edges connected) of each node.
    Traverse the list of roads (edges) to update the degree of each node.
    Sorting:
    Sort the degree array in ascending order. This allows assigning higher values to nodes with higher degrees in the subsequent step.
    Calculating Maximum Importance:
    Initialize variables to track the current value and the total sum.
    Iterate over the sorted degree array, multiplying each degree by an incrementing value, and add the result to the sum.
    Result:
    The final sum represents the maximum importance, calculated by strategically assigning higher values to nodes with higher degrees.
    By sorting the degrees and assigning incremental values, the approach ensures that nodes with higher connectivity contribute more to the overall importance, thus maximizing the total importance.
    ✨ Timelines✨
    00:00 - Introduction
    #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #newyear2024

Komentáře • 43

  • @komalsingla6032
    @komalsingla6032 Před měsícem +10

    MIK, really you are gem. I felt happy that mujhe apka channel mila. From long time, I did not do DSA, hence I followed your channel, which actually hit the mark ki beginner kaise sochega. I have been following your channel from last 5-6 months and really abhi intuition build hone laga hai.
    I actually solved this question on my own using Map and PriorityQueue, I came to see optimised thought.
    I actually recommend your channel to my friends, really helped me lot.
    Please don't stop teaching and intuition build krna and story ce code krna, is actually a plus for this channel because har koi leetcode contest ke level ka person nahi hota...
    Awesome....🙂

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

      Made my day 🙏❤️🙏

    • @ujjwal7317
      @ujjwal7317 Před 29 dny +1

      @@codestorywithMIK Yes sir thanks a lot for your diligent efforts in making us understand dsa concepts easily!

    • @ShivamGupta-dm7kf
      @ShivamGupta-dm7kf Před 29 dny +1

      Amazing

  • @mayukhbhowmik934
    @mayukhbhowmik934 Před měsícem +2

    I just solved it using map twice,and in a very legthy method.....But your approach gave me the twist and eye of observation...thanks mik...

  • @Sandeepvadlamani18
    @Sandeepvadlamani18 Před měsícem +12

    I have been watching your videos from 3 months and your explanations are too good just wanted to say thank you. Keep coming with more and more content every day

  • @avinashkumar8147
    @avinashkumar8147 Před měsícem +8

    Solved it before just came here to thank you sir. Your story to code approach helped me improve so much 🛐🙏🏻

  • @Akashkumar_12
    @Akashkumar_12 Před měsícem +4

    I have been watching your video when your subscribers 5k and your explanation is very good 😊 . Thank you so much 🙏.

  • @tanishchordia4813
    @tanishchordia4813 Před měsícem +11

    Hey mik a small request please complete the dp concept and questions playlist We all wanna learn how to solve the game theory questions

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

      Why? Pehle segment tree krna chahiye

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

      @@xiaoshen194 bhaii syd tumhe thode din hi huye haii subscribe kiyee jo bhi purane subscribers hai they all know dp concepts and questions vaala playlist pichle 1 saal se pending padha haii toh but obvious phle vo complete hoga na but theeke we believe in mik vo krlegaa😍

  • @NoneNobe-c3e
    @NoneNobe-c3e Před 29 dny +1

    Bhaiyia ek video bna dijiye jisame constraint dekh kar pata kar ki konsi time complexity ka solution work kar jayega isame.

  • @saihiteshreddy850
    @saihiteshreddy850 Před měsícem +1

    thank you so much bro

  • @user-ym1nv1pw8i
    @user-ym1nv1pw8i Před 29 dny

    I have not studied graph but I was able to solve both questions with logic (LeetCode POTD 27 & 28 June)

  • @user-tz3ql5jd1n
    @user-tz3ql5jd1n Před měsícem +1

    Hello mik,
    I like your code story❤

  • @UECAshutoshKumar
    @UECAshutoshKumar Před měsícem +1

    Thank you!

  • @Buy_YT_Views_524
    @Buy_YT_Views_524 Před měsícem +2

    Radiate positivity and attract greatness! 💫

  • @aws_handles
    @aws_handles Před 29 dny

    Maine heap se banaya. But ye approach mast tha yaar

  • @manishgaming4638
    @manishgaming4638 Před měsícem +1

    I solved on my own, took some time

  • @gui-codes
    @gui-codes Před měsícem

    you are the best man. I have learned so much from you in last few weeks than any other resource. thanks a lot for making this channel

  • @B-Billy
    @B-Billy Před měsícem +3

    Me nodding 🤭when you say "Tum smj rhe ho na ma kya kehna chah rha hu"

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

    your explanation is masterpiece ...that's why i love to do leetcode POTD ....

  • @gauravbanerjee2898
    @gauravbanerjee2898 Před měsícem +1

    Thanks a lot bhaiya ❤❤ congrats for 54ksubs 🥳🥳

  • @KishanSingh-vc3re
    @KishanSingh-vc3re Před měsícem +1

    alraedy solved on own in single attempt, still here for your thought process

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

    Did in my own. Support++❤

  • @RohitRaj-hl6ji
    @RohitRaj-hl6ji Před měsícem

    I have a humble request can you please make a video on recent weekly contest question no 3.

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

    Bhaiya *palindrome substring* ka aapne *blue print* diya tha uske *variant* karwaiye please

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

    Bhaiya, please Leetcode 2035 par video bana do plzz...🙏🙏🙏 I request you bhaiya...

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

    when will youu start concept playlists, dp is incomplete.

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

    Bro counting sort is optimial in this case...

  • @himanshusharma9132
    @himanshusharma9132 Před měsícem +1

    bhaiya here 8:48 , the sum is 33 not 35 , rest is good

  • @aggarwalsachin4854
    @aggarwalsachin4854 Před měsícem +1

    8:21. sum is 33

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

      right bro sum is 33 not 35 @codestorywithMIK

  • @nikhilhaspe2734
    @nikhilhaspe2734 Před měsícem +1

    || JAVA SOLUTION ||
    class Solution {
    public long maximumImportance(int n, int[][] roads) {
    long[] degCnt = new long[n];
    long res = 0;
    for(int[] road : roads){
    degCnt[road[0]]++;
    degCnt[road[1]]++;
    }
    Arrays.sort(degCnt);
    for(int i=0; i

  • @visheshpandey9070
    @visheshpandey9070 Před měsícem +1

    My Solution using Priority Queue(MaxHeap):
    class Solution {
    public:
    long long maximumImportance(int n, vector& roads) {
    vector degree(n, 0);
    // Count the degree of each vertex
    for (const auto& road : roads) {
    degree[road[0]]++;
    degree[road[1]]++;
    }
    priority_queue pq;
    for(int i=0;i

  • @PratikDongare-bh2vs
    @PratikDongare-bh2vs Před měsícem

    start dp

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

    hello sir, I wrote the code differently is their any issue in the code....
    long long maximumImportance(int n, vector &roads)
    {
    unordered_map mp;
    for (auto &vec : roads)
    {
    int a = vec[0];
    int b = vec[1];
    mp[a]++;
    mp[b]++;
    }
    vector vec(mp.begin(), mp.end());
    sort(vec.begin(), vec.end(), [](const pair &a, const pair &b)
    { return a.second > b.second; });
    long long ans = 0;
    long long i = n;
    for (auto it : vec)
    {
    ans += it.second * i;
    i--;
    }
    return ans;
    }

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

    public long maximumImportance(int n,int[][]roads){
    int[]degree =new int[n];
    for(int[]road:roads){
    degree[road[0]]++;
    degree[road[1]]++;
    }
    int[]cnt=new int[n];
    for(int b:degree){
    cnt[b]++;
    }
    long sum=0,value=1;
    for(int i=0;i

  • @k-CE-OmkarPathak
    @k-CE-OmkarPathak Před měsícem +1

  • @aizad786iqbal
    @aizad786iqbal Před 29 dny +1

    only watching till 11:00
    I got some idea
    and was able to solve on my own ( had to use chatgpt for some syntax issues)
    class Solution {
    public long maximumImportance(int n, int[][] roads) {

    HashMap freq = new HashMap();
    for(int[] road:roads){
    int u = road[0];
    int v = road[1];
    freq.put(u, freq.getOrDefault(u,0)+1);
    freq.put(v, freq.getOrDefault(v,0)+1);
    }
    TreeMap sorted = new TreeMap((a, b) -> {
    int freqCompare = Integer.compare(freq.get(b), freq.get(a)); // Sort by frequency (descending)
    return (freqCompare != 0) ? freqCompare : Integer.compare(a, b); // Sort by key (ascending) for tie-breaking
    });
    sorted.putAll(freq);
    int[] cityValues = new int[n];
    int val = n;
    for(Map.Entry pair:sorted.entrySet()){
    int key = (int)pair.getKey();
    int value = (int)pair.getValue();
    cityValues[key] = val;
    val--;
    }
    long ans=0;
    for(int[] road:roads){
    int u = road[0];
    int v = road[1];
    ans += cityValues[u];
    ans += cityValues[v];
    }

    System.out.println(Arrays.toString(cityValues));

    return ans;
    }
    }