Maximum Total Importance of Roads - Leetcode 2285 - Python

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

КОМЕНТАРІ • 26

  • @IamAWESOME3980
    @IamAWESOME3980 3 місяці тому +6

    i seriously have no idea what this question is even asking. after watching this video, i still have no idea why the edge add up to a value of 6 in the first graph

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

      See u have to assign values to the nodes just that u have a max sum so just assign values to the nodes and add them up. If u have a and b node connected, if a has value 4 (not the node val but the value u assign) and other has 2, ulso u add up 6

    • @jadenschulz1004
      @jadenschulz1004 3 місяці тому +2

      2 + 3 = 6 duh (i am also confused)

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

      ​@@jadenschulz1004 Not 2 plus 3, see nodes 0 and 1 and there u have values 2 and 4 which gives u 6. The problem is to find what u assign the values there, if u had a 3 instead of 4, u would have gotten 5

    • @chandrur6941
      @chandrur6941 3 місяці тому +2

      I thought the same, but the explanation given by Neetcode is misleading. Assume edges represent the number of routes.
      According to the example:
      Node 2 has 4 routes,
      Node 1 has 3 routes,
      Nodes 0 and 3 have 2 routes each,
      Node 4 has 1 route.
      To maximize total importance, assign the highest number to the node with the most routes:
      Node 2 => 5 Importance (assume importance as priority)
      Node 1 => 4 Importance
      Node 3 => 3 Importance (Node 3 can also come first, but the answer will not change)
      Node 0 => 2 Importance
      Node 4 => 1 Importance
      Now add the importance between edges and return the result.
      So to answer your question, if we add the edges in first graph, we will get 5 as a result, which is incorrect as per the explanation. We need to add the importance, which is 4 + 2 = 6.

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

    man you make every problem look so easy. respect

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

    Thanks for uploading this
    This was a good question, the question had two distinct components to it

  • @CheeseDiablo
    @CheeseDiablo 3 місяці тому +7

    You can apply bucket sort here to avoid sorting the array of edge counts which gives you linear time instead of O(nlogn)

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

      I think for large n the overhead of initiating dsa for bucket/count sort outweighs nlogn sorting algorithms. Good to mention in interview but implementation like this is good enough

  • @jamestwosheep
    @jamestwosheep 3 місяці тому +2

    I love this explanation, it's so simple. I totally overthought this problem by making an entire adjacency list in my first step.

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

      Sameee but I was able to come up with the same solution but in java lol😅

  • @arijaa.9315
    @arijaa.9315 2 місяці тому

    This time the eplanation is so contradict at the begining, I ffind it hard to understand how summing the number of edges for nodes 0 and 1 to be 6 hen 2+3 = 6 then your explanation changed into different idea. I see all your videos that is why I am writing

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

    I'll always be grateful for your videos, kindly keep uploading the daily problem solutions, we all will be grateful for that

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

    This is the best explanation that i can ever get. Mind Blowing explanation. Bro i became a big fan.

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

    I don't understand the question and even your explanation what I must do
    EDITED:
    I understood the question. I didn't understand where we take values for vertexes

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

      Learn basics and find another video in the same topic that you can understand

    • @pineappl3pizzzasoju
      @pineappl3pizzzasoju 3 місяці тому +2

      Same, I have done a few graph problem and am comfortable traversing dfs/bfs. But this problem in particular, I am having a hard time understanding what it wants.

    • @abhishekkumar-fe8lw
      @abhishekkumar-fe8lw 3 місяці тому

      @@pineappl3pizzzasoju You need to assign the greatest value to the most important road to maximiize the sum.
      The most important road is the one which has been visited the most.
      Just find the degree of al the node,and sort it,the one with the highest degree is most important.
      Hope you understood it.

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

      You have a 2D array. But consider it as a 1D array. store the occurrence of a number using arr[0] and arr[1] for each subarray in a 1D array. That is the degree of a node. Now sort the degrees in ascending order. Then start a counter from 1 to the number of degrees and multiply the counter to the degree and keep on adding it to a sum. Return that sum as answer.

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

      @@abhishekkumar-fe8lw Thank you, I was able to solve it after understanding that the key most important thing is to assign the greatest value to the city with most edges(roads) 🙏

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

    I solved it on my own but find your solution a bit compact. Happy to learn a better way.

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

    Why start out with the more complex case and just go with the simple ... and shorten the length of the tutorial
    Probably just me and no offense I also have a bit of OCD but it seems like many of these videos could be condensed quite a bit