evaluate division | evaluate division leetcode | leetcode 399 | graph dfs

Sdílet
Vložit
  • čas přidán 27. 07. 2024
  • Problem Link - leetcode.com/explore/challeng...
    Subscribe for more educational videos on data structure, algorithms and coding interviews - czcams.com/users/NareshGupta?s...
    September Challenge - leetcode.com/explore/challeng...
    Code Repository - github.com/naresh1406/youtube...
    August LeetCoding Challenge Playlist: • LeetCode August Challenge
    July LeetCoding Challenge Playlist: • LeetCode July Challenge
    June LeetCoding Challenge Playlist: • LeetCode June Challenge
    May LeetCoding Challenge Playlist: • LeetCode May Challenge
    LeetCode Recent Contest ProblemsPlaylist: • Leetcode
    LinkedIn - / nareshiitg
    Instagram - / naresh_gupta_
    Facebook - / 2784412725174003
    Quora - qr.ae/pN2M0x
    #Graph #DFS #Division #Evalute #Code #Interview #Practice #September #Leetcode #Medium #399 #Algorithm #DataStructure #Java #Preparation #NG #nickode #CookCodeTravel #CCT

Komentáře • 47

  • @NareshGupta
    @NareshGupta  Před 3 lety +11

    Time Complexity - O(Q * (V + E)), where Q - Quereis, V - Number of Vertices, E - Number Edges (length of values).
    Space Complexity - O(V + E).

  • @gilbertlopez
    @gilbertlopez Před 3 lety +5

    Hey man, just wanna say I enjoy your videos on these monthly challenges! My data structures are a little rusty and other times they help me understand the problem better so these are a huge help and I really hope you continue making them!

    • @NareshGupta
      @NareshGupta  Před 3 lety

      Thanks and welcome to channel, keep watching. Yes, definitely I will.

  • @0xVantwoutMaarten
    @0xVantwoutMaarten Před 4 měsíci

    what a champ, happy I did not have to do this problem on my own ❤‍🔥

  • @ikramulmurad
    @ikramulmurad Před 3 lety +1

    You're helping me a lot to keep coding!
    Whenever I can't get the idea behind any problem, then I immediately search your video on youtube. Even if the problem is very complex, your solution is simple enough to get it.

  • @devindas1669
    @devindas1669 Před rokem +1

    Explained clearly and quickly. Well done, brilliant answer. Thank you!

  • @ankitbatra9832
    @ankitbatra9832 Před 3 lety +1

    Your explanations are really thorough, loved your videos. Keep contributing! :)

    • @NareshGupta
      @NareshGupta  Před 3 lety

      Thank you! Will do! Welcome to Channel.

  • @ChristianESL
    @ChristianESL Před 3 lety +1

    you are amazing. I have seen a couple of explanations from your channel and they are good. New subscriber :P

    • @NareshGupta
      @NareshGupta  Před 3 lety

      Thanks and welcome to channel, keep watching and solving ds algo problems.

  • @janaarthananselvarajan264
    @janaarthananselvarajan264 Před 5 měsíci

    This is not dfs but a normal recursive function to iterate the hashmap
    Dfs deals with a map inside the node and go recursive with the next next nodes.

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

    I am a new subscriber but i feel like these are the best explanations out there :)))

    • @NareshGupta
      @NareshGupta  Před 3 lety

      Thanks and welcome to channel, keep watching and sharing.

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

    Thanks a lot, you make look things so easy.

  • @TheAuthorityOf
    @TheAuthorityOf Před rokem

    Excellent explanation

  • @theTacoKing640
    @theTacoKing640 Před 2 lety

    Really high-quality explanation. TY!

  • @saimanojkadiyala
    @saimanojkadiyala Před 3 lety +5

    Why do we need to check if the ans returned is -1.0. Is there any case where the ans is returned as -1.0 after a DFS call.
    If any of the vertex is not present in the graph we return -1.0 immediately.
    if (ans != -1.0)
    return ans * node.val;
    EDIT :
    There is a scenario where the two vertices belong to two different "connected components" where this check is required.

  • @arpanbanejee5143
    @arpanbanejee5143 Před 2 lety

    Nice explanation! Thank you!
    One suggestion from my side- pls give a dry run first and explain the edge cases as well, like why are we checking the and for -1 even when we have a case to check and return -1 before calling DFS again etc.

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

      Thanks for feedback, Yes I started in my recent videos.

  • @sugandhm2666
    @sugandhm2666 Před 2 lety

    Really good explanation

  • @KuldeepSahu-sq3cq
    @KuldeepSahu-sq3cq Před 2 lety

    Great ❤️

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

    please analyze the time complexity after the code also. It will help us in the interviews.

    • @NareshGupta
      @NareshGupta  Před 3 lety +1

      Actually, I used to do that but today this video become very long and missed that part. Thanks, I will take care from next video, for now, I added in PIN comment.

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

    This code will not work for :
    equations =
    [["x1","x2"],["x2","x3"],["x3","x4"],["x4","x5"]]
    values =
    [3.0,4.0,5.0,6.0]
    queries =
    ["x2","x4"]
    when going from x2 to x4 it will consider all edges from x2 which also contains an edge from x2 to x1 which is 1/3 and will add that to result calculation as well, so instead of expected answer 20, it returns 0.33

  • @nitingoyal5515
    @nitingoyal5515 Před 2 lety

    great solution, thanks a lot

  • @maksoodansari5262
    @maksoodansari5262 Před rokem

    At line number 23, condition should be OR not AND!

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

    Thanks for the great solution again!! very clear and easy understanding. I have one question about a test case like [["a","b"],["b","c"],["bc","cd"]], i'm not sure how the graph should be visualized with the case of "bc" and "cd", how are they supposed to be connected with the graph a -> b -> c. Thanks in advance

    • @NareshGupta
      @NareshGupta  Před 3 lety

      Thanks, don't think bc and cd as product of two variables this is new different individuals variables bc, cd are two independent vertices of graph.

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

      This is where I gave up. The problem just got a lot more complex.

    • @garvitkumargupta3306
      @garvitkumargupta3306 Před 2 lety

      @@saimanojkadiyala same

  • @vishalgoel6323
    @vishalgoel6323 Před 3 lety +1

    Hi, i have a query suppose
    Input: equations = [["a","b"],["b","c"]], values = [2.0,3.0], queries = [["a","c"],["b","a"],["ac","ba"]]
    It is giving output [6.00000,0.50000,-1.00000]
    But i think for query ["ac","ba"] output should be 0.333333 as ac / ba == c/b but instead it is showing -1.00000 ?

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

      ac, ba is not a * c and b * a it is independent variable and vertices of the graph.

    • @vishalgoel6323
      @vishalgoel6323 Před 3 lety +1

      @@NareshGupta Yeah i got it. These are basically variables.

    • @AnandKumar-kz3ls
      @AnandKumar-kz3ls Před 2 lety

      @@vishalgoel6323 yes thats why inputs are in string otherwise it will be in char

  • @osiris1102
    @osiris1102 Před 2 lety

    Brilliant video! But the pronunciation of "neighbours" was horrible.

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

      Thanks for feedback will work on it.

  • @AnandKumar-kz3ls
    @AnandKumar-kz3ls Před 2 lety +1

    thanks for the video My CPP solution -
    typedef unordered_map Graph;
    class Solution {
    public:
    Graph graph;
    void buildGraph(vector& equations,vector& values){
    for(int i=0;i

    • @Rajat_maurya
      @Rajat_maurya Před rokem

      can you explain Graph graph;
      and typedef?
      btw nice way of writing choosing of variable name properly