Binary Tree Max Path Sum (LeetCode Day 29)

Поділитися
Вставка
  • Опубліковано 12 лис 2024
  • Given a binary tree with values in nodes, find a path with the maximum sum of values. This coding interview problem is quite similar to other tree problems like "find height" or subtrees or any kind of dp on trees - it's just about thinking what should be returned by DFS.
    Leetcode April Challenge - leetcode.com/e...
    Subscribe for more educational videos on algorithms, coding interviews and competitive programming.
    Github repository: github.com/Err...
    Live streams on 2nd YT channel and on Twitch: / errichto2 & / errichto
    FB and Twitter: / errichto & / errichto
    Frequently Asked Questions: github.com/Err...
    #Coding #Programming

КОМЕНТАРІ • 78

  • @user-mr-m12312
    @user-mr-m12312 4 роки тому +30

    This problem is something similar to leetcode day 11 problem about tree's diameter, wich was quite hard for me, but after your explanations I was able to solve this by my own, so thx for you work Errichto! :)

    • @Errichto
      @Errichto  4 роки тому +14

      Hah, you are right. I didn't even remember that there was Diameter problem 2-3 weeks ago :D

  • @coderaspirant
    @coderaspirant 4 роки тому +4

    With due respect I just say your programs are very clear in concept and simple to implement. It naturally feels that it's so simple to understand the logic and implement it. Thanks for do it so effortlessly.

  • @BedoEbied
    @BedoEbied 4 роки тому +24

    Thank you this was clear and concise. We love your drawings.

  • @eloyhz
    @eloyhz 4 роки тому +2

    What so great explanation, including the wrong answer, you are a grand master!

  • @vivekdubey2068
    @vivekdubey2068 4 роки тому +1

    Thanks for explaining so well.
    The last part was similar to Kadane's algo.

  • @Learner010
    @Learner010 4 роки тому +1

    successfully completed 30 day leetcode challenge !!! thank you

  • @niebhasanneom8211
    @niebhasanneom8211 4 роки тому +1

    Your videos have high ratio of likes to dislikes . Please continue making these kind of problem solving regularly. Thanks.

  • @ThatPsdude
    @ThatPsdude 3 роки тому

    This was an amazingly simple explanation for this, thank you!

  • @vasachisenjubean5944
    @vasachisenjubean5944 4 роки тому

    Literally the best programmer on UA-cam.

  • @prashanthvaidya
    @prashanthvaidya 4 роки тому +6

    I was signed out while watching this.
    Signed in again just to like it. :)
    Thankyou Errichto! /\
    I found this difficult tbh and your solution was extremely elegant.
    Will you be doing the May challenge as well?

    • @tailarsen6961
      @tailarsen6961 4 роки тому

      I believe he mentioned in the last video that one LeetCode challenge is enough for him. Correct me if I'm wrong, but what a sad information that we would miss this content.

  • @mohitsingh-nf5vl
    @mohitsingh-nf5vl 4 роки тому +1

    how does dfs return value matter as it is not updated .The value main function is returning is answer not return value of dfs

  • @pranjalchoubey5929
    @pranjalchoubey5929 4 роки тому

    Beautifully explained!

  • @kevin_m7
    @kevin_m7 4 роки тому

    Great content! I hope you do participate in the harder May questions

  • @jdhp3696
    @jdhp3696 4 роки тому

    Thank you once again for the awesome explanation.

  • @vishalchaurasia96
    @vishalchaurasia96 4 роки тому +1

    Hi errichto, I can't tackle graph colouring problem from Atcoder ABC. Give some advice to how I tackle problems related to graphs.

  • @syeda.k.2934
    @syeda.k.2934 4 роки тому

    Loved the explanation

  • @736939
    @736939 4 роки тому

    how to produce the input like in the code from left to right for the tree? If I need to add inputs for tree from the command line? Thanks

  • @poonamyadav-qz7yt
    @poonamyadav-qz7yt 3 роки тому

    Hi Errichto, where are we using variable answer from line 21 ?

  • @andreyavdeev5239
    @andreyavdeev5239 4 роки тому +1

    Thank you very much for yours videos they are super helpful. I've a question to your implementation. Will it work if in the tree will be only negative values? Thank you in advance!

    • @piyushverma415
      @piyushverma415 2 роки тому +1

      yes answer will be a 0 then
      simple!!!!!!

  • @franky0226
    @franky0226 4 роки тому

    Thanks a ton!!!! i was struggling with this

  • @zihanbayeed42
    @zihanbayeed42 4 роки тому

    Can you do a tutorial for Hash Tables and Maps? That is another harder concept to grasp. Love your tutorials. Thank you.

  • @mogovanjonathan
    @mogovanjonathan 4 роки тому +4

    hy Erritcho wich should i learn after c++: java or python? Thanks for answering!

    • @Errichto
      @Errichto  4 роки тому +7

      google -> which programming language should I learn?
      (if you do it only for competitive programming, it should be c++)

    • @mogovanjonathan
      @mogovanjonathan 4 роки тому +1

      @@Errichto thanks for answering! Subscriber from Romania

  • @nhantran0
    @nhantran0 4 роки тому +2

    Since I've just watched your DP tutorials and this, is the approach straightforward for these problems?
    Find number of paths in the tree where their path sum (by nodes' value) is:
    - at most K
    - equal K
    - at least K.

    • @nhantran0
      @nhantran0 4 роки тому

      Another problem is:
      Find maximal path sum by nodes' value in the tree where the number of nodes is at most K / equal K / at least K.

    • @Errichto
      @Errichto  4 роки тому +4

      It's quite hard to do these better than O(N^2). I think that it's possible only if path length means the number of nodes, not the sum of values. Then it is bottom-up dp on a tree with "smaller to greater" principle.

  • @mohitsinha1994
    @mohitsinha1994 4 роки тому

    beautiful perfect explaination sir. Thank you.

  • @incotaku
    @incotaku 4 роки тому

    Which whiteboarding / free-drawing software does Errichto use for this presentations?

  • @SaurabhSingh-ch6nc
    @SaurabhSingh-ch6nc 4 роки тому

    Love it bro!
    You r the our legend 😊

  • @pruthvirajk6019
    @pruthvirajk6019 4 роки тому

    one word Fan of You

  • @pruthvirajk6019
    @pruthvirajk6019 4 роки тому

    if you dont need to consider that negative path then why didnt we take max(x,y,0)+root->val ....Because there x=-1 y=0 so for its parent if we are returning a max path with node 2,then return max(x,y,0)+root->val will be 0+2 i.e 2.
    Could you explain this plz

  • @ivailotenevv
    @ivailotenevv 4 роки тому

    Awesome content! What program do you use for drawing ?

  • @hscott8052
    @hscott8052 3 роки тому

    Great great great!

  • @bhawnag4
    @bhawnag4 3 роки тому

    what if the root is itself negative?

  • @mandeepubhi4744
    @mandeepubhi4744 4 роки тому

    Could you cover Backtracking?

  • @ishanpandey2949
    @ishanpandey2949 4 роки тому

    This problem was always there on leetcode , I don't understand what's new

  • @madiyar8079
    @madiyar8079 4 роки тому +4

    3 adblockers 😂

    • @Errichto
      @Errichto  4 роки тому +4

      I don't even remember why I need more than 1...

  • @god-speed03
    @god-speed03 3 роки тому

    Did he just read, solved that question and explained it in under 9 minutes

  • @secretmystery8305
    @secretmystery8305 4 роки тому +1

    Next stream when?

    • @Errichto
      @Errichto  4 роки тому

      within a week, I think
      watch out for schedule update at www.twitch.tv/errichto

    • @secretmystery8305
      @secretmystery8305 4 роки тому

      @@Errichto oh nice. This is great. I am waiting for your next stream. I love your stream so so much. Which day you stream please tell me at first please.

  • @pruthvirajk6019
    @pruthvirajk6019 4 роки тому

    You are awesome Awesome Awesome

  • @srikantjenakumar
    @srikantjenakumar 4 роки тому

    Nice

  • @ayyappahemanth7134
    @ayyappahemanth7134 4 роки тому

    Is it okay to start competitive programming with python

  • @gauravkumarpandit7022
    @gauravkumarpandit7022 4 роки тому

    Ladies and gentlemen this is .. 😊😊

  • @SaurabhYadav-wj7zm
    @SaurabhYadav-wj7zm 4 роки тому

    What the teddy is looking at? Is he sad?

  • @serserserserserserser
    @serserserserserserser 4 роки тому

    Please make some tutorial video about Graph theory:)

  • @vincentmarquez3096
    @vincentmarquez3096 2 роки тому

    How is this a LC hard but also minimum height trees is a LC medium -_-

  • @iasith
    @iasith 4 роки тому

    Hi errichto, how can I become that good at programming like you and how I can get all that knowledge that you have in c++ about language and problem solving, I'm new in this world. I will thankful if you help me, with books names and stuff like that...
    PD: I don't speak english, then I apologize for my writting.

    • @Errichto
      @Errichto  4 роки тому +3

      for c++, find any tutorial or course online
      for algorithms, just do problems and read this github.com/Errichto/youtube/wiki/How-to-practice%3F

    • @iasith
      @iasith 4 роки тому

      @@Errichto Thank you so much!!

  • @sahilkaushik6856
    @sahilkaushik6856 4 роки тому

    As I had already commented below but no one wants to be a mentor.
    Could I find someone who is willing to solve daily 4-5 problems with me please 🙇‍♀️

  • @kunalmamgain
    @kunalmamgain 4 роки тому

    why no hand raised bye :(

  • @Vijay-ph4gb
    @Vijay-ph4gb 4 роки тому +1

    *Errichto please conduct some contest on hackerrank for your subscribers please at least monthly once*

    • @Errichto
      @Errichto  4 роки тому +4

      Does Hackerrank conduct contests at least monthly? :D

    • @Vijay-ph4gb
      @Vijay-ph4gb 4 роки тому

      @@Errichto No they won't so I do want you to conduct it.

    • @Errichto
      @Errichto  4 роки тому +1

      @@Vijay-ph4gb Creating a contest requires a huge amount of effort and time.

    • @Vijay-ph4gb
      @Vijay-ph4gb 4 роки тому

      @@Errichto please do it for the subscribers.... Like me.

    • @10xGarden
      @10xGarden 4 роки тому

      hackerrank is stupid

  • @prakashshukla3558
    @prakashshukla3558 4 роки тому

    where is your silver tick from the youtube?

    • @Errichto
      @Errichto  4 роки тому +1

      Still coming, I guess

  • @TwoTeaTee
    @TwoTeaTee 4 роки тому

    Please participate in May challenge.

  • @syeda.k.2934
    @syeda.k.2934 4 роки тому +2

    When will increase font??????? This is my 3re effin comment.