Binary Tree Cameras | Leetcode | DP on Trees
Vložit
- čas přidán 13. 09. 2024
- good coding problem and an even better solution is here ;)
Enjoy watching!
Problem link: leetcode.com/p...
Solution link: leetcode.com/s...
alternate link: ideone.com/5oFPfG
Super useful books for algo ds and programming fundamentals!
1. Introduction to Algorithms by Cormen: amzn.to/35AmQqu
2. The Algorithm Design Manual: amzn.to/2K9RGPq
3. Fundamentals of Data Structures in C++: amzn.to/2LCwIsN
4. Object-Oriented Programming by E Balagurusamy: amzn.to/2Xxmdtr
5. Head First Java: amzn.to/39kb44K
6. Cracking the coding interview: amzn.to/3iDOHLK
7. Database System concepts: amzn.to/3pisuFQ
8. Operating Systems: amzn.to/39fcmis
9. Discrete Mathematics: amzn.to/2MlgCE6
10. Compiler Design: amzn.to/3pkYvx2
Dude, the intro is sooo funny 😂😂😂😂 I had to like it
😂
I would like to thank you so much for bringing up such nice intuitive approaches !!
You are a true gem!
I hope that I could press that like button multiple times !!
Thanks Shashank :)
Loved the intro!
yes , it got me hooked
Kaafi cool ban gye aap pehle ek min me😂
Thankyou so much bro, I have used up a whole day to understand this. I have watched this video around 8 times coz I can't able to implement it due to the edge cases w/o referring to your code. Your content is no doubt exceptional, Thanks for that.
if(root == null) {
if(willPlace) return 1001;
return 0;
}
You're welcome and thanks so much for the nice words :)
Keep learning and coding.
Thanks👍 one day every1 will came to know about the precious content of your channel ..
So nice of you
great explanation. i missed the case where parent can cover a child,, and so missed that state and couldn't figure out what was wrong..Also can you please explain the greedy solution and first explain why it works... That blew my mind
"Who can explain it better than Kartik Arora?🤣🤣🤣🤣" . I have not watched the full video yet , but my answer will be : Kartik Arora himself . Btw great job !
Thanks Sujoy :)
could you explain the last condition dp(u,0,0) for a general tree with more than 2 subtrees(the code)
bhiya ji to maze maze me samjha dete hain aur itni aasani se samjh bhi aa jata hai.cha gye bhiya ji.
like and subscribe zaroor kro bhaiyon
yeh hui na baat, thankss :D
Where were you all these time....spent so much time on this problem already
Mastering dp from this channel 🔥
Glad to know man :)
Sweet and Simple Explaination really loved it
15:03, dp( u , 0 , 0 ) than why need of Case 1 and Case2. ( we have to return inf ) As we can see if the current node and parent node have not camera then if we place the camera its child node then the child node can only monitor the current node, not the parent node( no one can monitor) .
Anyone can tell me please ?
Parent node is monitored by the camera in grandparent node i guess
Nice tutorial, Kartik. Just one suggestion. I think the leaf case is not required to be handled. The base case (root == NULL) and the recursion itself handle that scenario. Thanks
thank you sir , i struggled a lot while solving, you made it easier .
I think whenever you upload a video, you should mention that somewhere on Codechef Discuss, atleast that's how I found this amazing channel, maybe more people come across your channel this way!
Thanks Parth for the tip and the appreciation :)
Will try to share the videos on relevant platforms.
Intro was legendary
Unable to understand why is there a need of keeping the monitoring state?
why are we considering a case where we allow the parent also and the grand parent of current node also to not have the camera ? we do this for both left and right child and suppose it gives min answer ..wont it be wrong?
Time will be order of nlogn ig, only because of the cache ie dp array . We are using map here and not unordered map .
We can't use unordered map .
Also we can't take a 3d dp because the first parameter is a node and not an integer
Give a number to each node. unordered map node*, int.
Then make 3d array for dp.
@@AlgosWithKartik oh yes this idea is great .
Thanks a lot sir .
God Of DP :)
Thanks Bhuwanesh :)
Can you explain your base case when root==NULL ?
Why cant we always return 0?
if node X is not monitored and X expects one of the child nodes to have a camera but turns out X has no child nodes. Let's say now I call solve(X->left).
Then returning a 0 would be incorrect. I should return something that represents it is impossible to cover all the nodes now, given that X is not monitored.
Let me know if this clears your doubt.
please explain line sweep and suffix arrays.
super
great video sir,please make a video on how to make progress in codeforces contests,what to do if we are not able to solve div2c and div2d problems?
This seems like a modified version of knapsack
I completely encourage you to make more videos and work harder. You are doing a great job :), but I felt the problem could be explained a bit simpler. However, your videos are definity great and worth it!!
Thanks for the appreciation and the feedback :)
Great
if someone write bad about the features or anything , you will work on yourself ( no point of removing that comment )
i love your content btw
lol... in the starting of video, all of a sudden i lost my dizziness.
link is not opening
Sir please switch on the camera for the whole video... it feels more connecting...hope you understand:)
I do understand. I'll try to set it up properly so I can have the cam on for the entire video
@@AlgosWithKartikyes sir..thank you🙂
Another great video.
Can we extend this solution to a k-ary tree from this binary tree approach?
yes we definitely can!
Try solving it in O(N) time.
@@AlgosWithKartik thank you bhaiya
Great video 🔥
thankyou sir :D
can we memoize using 3D vector ??? how we will store TreeNode's address in vector??
Yes we can.
Give a number to each node of the tree.
@@AlgosWithKartik oh, Got it! thanks :)
Can it be done using BFS?
Not sure but I don't think so
can anyone explain line 34?
solution link is not working
I think you need to be logged in to leetcode for accessing that link.
adding ideone link in description instead.
@@AlgosWithKartik logged in but not working btw i understand the solution thanks (y)
happy to see how similar my code is to yours xD...
Uniteresting problem xdddddddddddd