Most Profitable Path in a Tree - Leetcode 2467 - Python

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


0:00 - Intro
3:00 - Understand problem
9:50 - Explanation
17:07 - Coding Explanation

leetcode 2467

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

Neet, the people that really are learning are the ones that value your explanations. The people that copy/paste code and dont learn anything are the ones that say your explanations are too long. I love the long explanations and thought process, that's where the true learning happens.

jayjw
Автор

If a coding video is 30 minutes long, it’s not just hard—it’s the final boss of coding pain. 💀🔥

JamesBond-mqpd
Автор

hey man, i watch your videos just because i love to hear your thought process. Thanks to you and your explainations i was able to solve this problem by myself in like 45 minutes or something, even then i came here to see what was your thoght process so that i am sure i didnt miss anything, so please do not change the way you explain things. Big appreciation for your videos. There are 100s of people on youtube explainging DSA problems, but the first person i search for whenever i face a problem is you.

kshitijgupta
Автор

Today, I have solved this problem without looking at the solution. Thanks to you, neetcode. This wouldn’t have been possible if I did not come across this channel.

sampreethvarri
Автор

dw neet, I like hearing about your thought process 🥺

razialghul
Автор

Even though I can't come up any shit about this problem, I still find this video super helpful. Thank you, and please keep uploading LeetCode Daily. I'll still need that for a long long while. XD thx

morrischung
Автор

I love your thought process, please keep in the Dry Runs. I love understanding the exact problems each of your approaches had since that is super helpful for learning what "not to do" rather than just a straightforward solution.

araneuskyuro
Автор

14:38 if you are like I was and struggling with the notion of "same time", what it means is that we are going to process all the neighbors of the current node and put it on the queue with the same timestamp; It's not possible to do everything at one time. I used to struggle with that.

On another note, I like it when you display all your thoughts process. It's true that sometimes I'm not in the mood for digressions but hey, I just skip until I'm gold.

sdemji
Автор

Hey Neetcode! Just wanna let you know that the thought process you share in your video showing how you arrive at the solution really helps me. It also gives me a sense of how close (or far) I was to figuring it out myself!

AdarshVishwakarma-yh
Автор

Very good explanation.You have saved the life a lot of programmers!

johnniewalkerjohnniewalker
Автор

One thing I did differently was traverse from root with a BFS and make a hashmap for each node and its distance to the root. That helped me with the traversal for Alice and Bob because I could just check if the next node was further from the root (for Alice) or closer (for Bob). This is probably less efficient, but I didn't realize you could traverse using the src, parent method in a tree (although it makes sense to do it that way).

For finding leaf nodes, it's also possible to have a boolean is_leaf that is set to false if we append anything to the queue for that node. I do like the idea you can just check the length. It feels like this problem had a lot of tricks that relate to how trees work.

gabrielfonseca
Автор

Couldn't come up with a solution to this one in reasonable time. It reminded me of the DP problem where they start on the same line and fall down gathering points but in that case you can move them line by line together which eliminates the need to check at which time nodes are visited by who.
I come to your videos mostly for the explanation personally, I can look at multiple code solutions directly on leetcode but having your thought process explained is the real value!
If this had been an interview problem I would be toast I fear :(

BSimone
Автор

I enjoyed this problem a lot and almost solved it on my own, just had a small bug when checking with bobs time. Thanks to you I could find my mistake.

paulgwydyon
Автор

I did it with dfs and came here to see optimal solution. I'm glad I got greedy solution from you.

Henok-
Автор

IMO, this way of explanation is more simple and rewarding to your viewers. I could go step by step and code it myself after understanding the thought process that you went through.

prashant
Автор

wow what a solution. Amazing!!
Please always share your thought process, solution is present everywhere. Thanks again!!

nsms-us
Автор

Hi there neet....
Just wanted to let you know, I have been solving leetcode like 6 months now, and at first i had no idea how to solve any problems(yes i had theory knowledge, but didn't know how to use it), So i used to watch your videos
But now I can solve majority of medium questions, but I still watch your daily video if you upload, because I would like to know what your perspective while solving the questions, it helps a lot...

TL;DR
Just don't change the way you make your videos

prajwals
Автор

Appreciate all your explanations, Nav! Some people might consider it a bit verbose sometimes, but I for one find it all quite helpful and insightful.

jamestwosheep
Автор

I like the detail of the explanations, even if it can be tangential. I prefer hearing all the steps so I can walk through and imagine how the solution would sound in interview.

jadonnielsen
Автор

Real talk- if you really want to *Understand* the problem or relevant nuance of the problem, hearing tangents not necessarily relevant to the solution but still relevant to the process are important. If people just want a solution they look on the solution tab. If they want to build understanding that is reasonable to an approach, we should watch the video and all free flow thought that comes with. Just like in an interview!

ZeroTrunks
join shbcf.ru