I've already made a solution for this problem but i thought it could be improved so i rerecorded it. If you notice any other problems in the NeetCode 150 (neetcode.io/practice) where the video solution could be improved, please let me know!
@floatingpoint76294 ай бұрын
thanks for this, the explanation is much better then the one before 👍
@jeysiva83674 ай бұрын
This explanation is better and clear, Thanks
@chronobytes9713 ай бұрын
Much better than the previous one! I have understood it at once. Thank you very much
@jrose20822 ай бұрын
you’re awesome dude
@dzcccccАй бұрын
Thank you for everything you do :)
@galkk33 ай бұрын
another option that I prefer to use regarding the res variable is to declare it as an array like res = [0] and then any time I want to use it it is like this: res[0] = ...
@bennycai755225 күн бұрын
I found one thing. When you do 1 + max(left, right), what if curr doesn't have left and right children? The height should be 0, but 1 + max(left, right) will make it 1.
@DerekGomez-n1wКүн бұрын
if curr is non-null, the height is 1.
@zhalzel3 ай бұрын
Great timing this explanation is super clean!
@benmyths4 ай бұрын
brother just now i started solving this problem and i see your latest video on it. W timing haha!
@davitmodebadze97074 ай бұрын
For a second I thought leetcode posted the daily problem earlier than usual
@mdrashedulhasanmr84564 ай бұрын
it made me recheck leetcode, twice
@mohanedomer90814 ай бұрын
same lmao
@juanmacias59224 ай бұрын
now I'll be really scared if this turns out to be the daily HAHA
@michaelroditis19524 ай бұрын
Me 2 got confused haha
@DerekGomez-n1wКүн бұрын
if you're confused by the return statement remember: height = 1 + max(left, right) diameter = left + right
@NikithM-vj6pn4 ай бұрын
I know it is a big thing to ask , but can you make short videos for all the 150 neetcode problems , suggesting the most important parts / techniques / approaches required to solve the problem? Huge thanks for your short videos they are helping for quick revision :)
@NikithM-vj6pn4 ай бұрын
could you do reverse linked list nodes in pairs of k?
@LuisSolorzano-p9u2 ай бұрын
Hey thanks for the video! When I was doing this problem I knew that I could use a global variable, but in bigger coding applications global variables should be avoided. Do you believe using global variables for interview sessions is okay? Is it too much to ask an interviewer if I'm allowed to use them rather than assume I can use them? Thanks!
@dzcccccАй бұрын
A bit late but I saw either a video or podcast with Neetcode where he mentioned he passed the variable as an argument instead of using global variable, and his interviewer was asking him how he could simplify it, and he said he believed that they wanted him to use a global variable to simplify it
@rryt0002 ай бұрын
can someone explain why the space complexity would be O(h)?
@hi-ew2ox2 ай бұрын
in this case since we're using recursion, the space complexity is based on the maximum number of nodes we're storing in the callstack. this would be equal to the height of the tree, since that is when you have reached the deepest part of the tree from the root. in the worst case, if the tree is completely vertical and all the nodes are just stacked on top of each other, the space complexity would be O(N) where N is the number of nodes. in the best case, it would be O(h), where h is the height, e.g. as mentioned in the video if the tree was balanced it would be O(logN) since theres a logarithmic relationship between the height and the number of notes (at level h in the balanced tree, there are 2^h nodes)
@dusvn14842 ай бұрын
I have same problem to understand this so I will try to help you on the shortest way. The space complexity of recursion dependent on maximum recursive calls at the moment.So as you can see on neet example maximum deep where we can be is the height of tree which value is 3 in video example. Log with base 2 of N where N is equal to 8 is 3. So we see the relation of log base 2 of 8 = height of the tree. Write me some feedback if this help you :D
@mohanedomer90814 ай бұрын
if you have the time plz do 493. Reverse Pairs . I couldn't understand it at all plz
@Emorinken2 ай бұрын
I was wondering why this had just a little over 200 likes, then i realized it was just posted a month ago