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

Поділитися
Вставка
  • Опубліковано 11 жов 2024
  • Whatsapp Community Link : www.whatsapp.c...
    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/MAZ...
    Leetcode Link : leetcode.com/p...
    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/MAZ...
    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

КОМЕНТАРІ • 43

  • @komalsingla6032
    @komalsingla6032 3 місяці тому +11

    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  3 місяці тому

      Made my day 🙏❤️🙏

    • @ujjwal7317
      @ujjwal7317 3 місяці тому +1

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

    • @ShivamGupta-dm7kf
      @ShivamGupta-dm7kf 3 місяці тому +1

      Amazing

  • @Sandeepvadlamani18
    @Sandeepvadlamani18 3 місяці тому +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 3 місяці тому +8

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

  • @mayukhbhowmik934
    @mayukhbhowmik934 3 місяці тому +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...

  • @iamnoob7593
    @iamnoob7593 23 години тому +1

    Superb explanation

  • @Akashkumar_12
    @Akashkumar_12 3 місяці тому +4

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

  • @tanishchordia4813
    @tanishchordia4813 3 місяці тому +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 3 місяці тому

      Why? Pehle segment tree krna chahiye

    • @tanishchordia4813
      @tanishchordia4813 3 місяці тому

      @@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 3 місяці тому +1

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

  • @saihiteshreddy850
    @saihiteshreddy850 3 місяці тому +1

    thank you so much bro

  • @gui-codes
    @gui-codes 3 місяці тому

    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

  • @Lakshya-f4l
    @Lakshya-f4l 3 місяці тому

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

  • @Hereitus
    @Hereitus 3 місяці тому

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

  • @B-Billy
    @B-Billy 3 місяці тому +3

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

  • @KishanSingh-vc3re
    @KishanSingh-vc3re 3 місяці тому +1

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

  • @gauravbanerjee2898
    @gauravbanerjee2898 3 місяці тому +1

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

  • @PradipLabade-o3o
    @PradipLabade-o3o 3 місяці тому +1

    Hello mik,
    I like your code story❤

  • @aws_handles
    @aws_handles 3 місяці тому

    Maine heap se banaya. But ye approach mast tha yaar

  • @UECAshutoshKumar
    @UECAshutoshKumar 3 місяці тому +1

    Thank you!

  • @ugcwithaddi
    @ugcwithaddi 3 місяці тому

    Did in my own. Support++❤

  • @RohitRaj-hl6ji
    @RohitRaj-hl6ji 3 місяці тому

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

  • @manishgaming4638
    @manishgaming4638 3 місяці тому +1

    I solved on my own, took some time

  • @visheshpandey9070
    @visheshpandey9070 3 місяці тому +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

  • @nikhilhaspe2734
    @nikhilhaspe2734 3 місяці тому +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

  • @knowledgeseekers303
    @knowledgeseekers303 3 місяці тому

    when will youu start concept playlists, dp is incomplete.

  • @k-CE-OmkarPathak
    @k-CE-OmkarPathak 3 місяці тому +1

  • @pokeindia5361
    @pokeindia5361 3 місяці тому

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

  • @priyanshkumar17
    @priyanshkumar17 3 місяці тому

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

  • @prajitbanerjee8226
    @prajitbanerjee8226 3 місяці тому

    Bro counting sort is optimial in this case...

  • @aggarwalsachin4854
    @aggarwalsachin4854 3 місяці тому +1

    8:21. sum is 33

    • @gabruboy1690
      @gabruboy1690 3 місяці тому

      right bro sum is 33 not 35 @codestorywithMIK

  • @himanshusharma9132
    @himanshusharma9132 3 місяці тому +1

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

  • @izanahmad5705
    @izanahmad5705 3 місяці тому

    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 3 місяці тому

    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

  • @PratikDongare-bh2vs
    @PratikDongare-bh2vs 3 місяці тому

    start dp

  • @aizad786iqbal
    @aizad786iqbal 3 місяці тому +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;
    }
    }