Find Minimum Diameter After Merging Two Trees - Leetcode 3203 - Python

preview_player
Показать описание


0:00 - Read the problem
0:30 - Drawing Explanation
15:46 - Coding Explanation

leetcode 3203

#neetcode #leetcode #python
Рекомендации по теме
Комментарии
Автор

For those of us who are still here trying to solve a problem like this during this time of the year, kudos to you! Kudos to NeetCode too~

hongyihuang
Автор

Don't waste too much time on this problem, just watch the solution and learn :D

trueinviso
Автор

Thank you neetcode you changed my life for the better. Thank you leetcode for the wonderful xmas gift.

focminging
Автор

thank you for all what you are doing, you are the best leetcode teacher on youtube.

topsy_kreds
Автор

I am glad and sooo proud of myself that i came up with the same solution like you and i was able to code it up!! Practice really pays off

KrystianRatajczyk-korb
Автор

ur the best, happy christmas n happy new year buddy

jaatharsh
Автор

Great explanation, as always. Thank you!

nayankhanna
Автор

Very good explanation, thank you neetcode!!!

RedCrater
Автор

I have watched it like 4 times already and still can't wrap my head around the whole problem 😢

-ArnobBiswas
Автор

solved it within 20min, all it takes is the observation, the actual solution is straightforward to be honest.

codygao
Автор

oh i got the first and second max height of all the nodes and stored them in list, i knew that diameter can be in either three or both tree but i was not not able to guess which node should i take to connect bothe trees… so i again do a dfs to reroot tree on all nodes and got the minimum height of tree of all possible trees and joined them. The solution was linear time so it passed, but it gave me a headache to implement

akshatpandey
Автор

This Christmas eve daily challenge is diabolical

leetprep
Автор

Can you redo the reconstruct itinerary problem and go over the Hierholzer's algorithm for eulerian paths

Chris-hzlj
Автор

i was able to think of this approach but could not code it

prajapati-suraj
Автор

I found the minimum diameter after merging the tree (without the simple formula, just manually going through all nodes and finding the minimum longest path from any node in a tree and adding them for both trees) but forgot to also consider that a larger tree can still contain the diameter by itself.

cooldudeachyut
Автор

why did we define n and m if we never used them though ?

business_central
Автор

It feels good when you can solve hard question in 15 minute without extra help

unlucky-
Автор

Help me understand why we divide by 2? That’s the only part not making sense imo

yankeehater
Автор

Meh, I came here because I didn't want to code up my solution, since it seems tiresome, so I hoped to find a simpler one. But you got the exact same one lol

floriankubiak
Автор

Can someone explain to me why the final answer is like the max(d1, d2, 1+ceil(d1/2)+ceil(d2/2))? I understand the 3rd term where we are trying to minimize the diameter after merging the two trees as asked in the problem and also explained in the video, but why exactly are we also considering d1 and d2 individually? I did not understand it.

-ArnobBiswas
welcome to shbcf.ru