Binary Tree Cameras | Live Coding with Explanation | Leetcode - 968

  Рет қаралды 10,911

Algorithms Made Easy

Algorithms Made Easy

Күн бұрын

Пікірлер: 59
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 жыл бұрын
We hope you all are enjoying our videos!!! Don't forget to leave a comment!!! Please like the video to support us!!! Questions you might like: ✅✅✅[ Tree Data Structure] : kzbin.info/aero/PLJtzaiEpVo2zx-rCqLMmcFEpZw1UpGWls ✅✅✅[ Graphs Data Structure] : kzbin.info/aero/PLJtzaiEpVo2xg89cZzZCHqX03a1Vb6w7C ✅✅✅[ January 2021 Leetcoding Challenge] : kzbin.info/aero/PLJtzaiEpVo2wCalBcRcNjXQ0C6ku3dRkn ✅✅✅[ February 2021 Leetcoding Challenge] : kzbin.info/aero/PLJtzaiEpVo2wrfvII0eZQsPm-MZCmHodm ✅✅✅[ March 2021 Leetcoding Challenge] : kzbin.info/aero/PLJtzaiEpVo2zH-YC5ZiptbAvw2QZkmyk9 ✅✅✅[ April 2021 Leetcoding Challenge] :kzbin.info/aero/PLJtzaiEpVo2z9PpcJcsl5j3RXutiTU-GB ✅✅✅[ December 2020 Leetcoding Challenge] : kzbin.info/aero/PLJtzaiEpVo2xo8OdPZxrpybGR8FmzZpCA ✅✅✅[ November 2020 Leetcoding Challenge] : kzbin.info/aero/PLJtzaiEpVo2yMYz5RPH6pfB0wNnwWsK7e ✅✅✅[ August 2020 Leetcoding Challenge] : kzbin.info/aero/PLJtzaiEpVo2xu4h0gYQzvOMboclK_pZMe ✅✅✅[ July 2020 Leetcoding challenges] : kzbin.info/aero/PLJtzaiEpVo2wrUwkvexbC-vbUqVIy7qC- ✅✅✅[ June 2020 Leetcoding challenges] : kzbin.info/aero/PLJtzaiEpVo2xIPptnCvUtKrUcod2zAKG ✅✅✅[ May 2020 Leetcoding challenges] : kzbin.info/aero/PLJtzaiEpVo2wRmUCq96zsUwOVD6p66K9e ✅✅✅ Cracking the Coding Interview - Unique String: kzbin.info/aero/PLJtzaiEpVo2xXf4LZb3y_BopOnLC1L4mE Struggling in a question?? Leave in a comment and we will make a video!!!🙂🙂🙂
@heyrmi
@heyrmi 3 жыл бұрын
Everyday it gets a little easier. Thank you both of you.
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 жыл бұрын
Our pleasure!
@johnademola528
@johnademola528 3 жыл бұрын
Just exactly. They make it easier for me everyday. Thanks guys
@sharma.ajay2612
@sharma.ajay2612 3 жыл бұрын
1st approach that came in mind is to do level order traversal and save that in Array List then add the odd list count i.e 1st, 3rd list to get the minimum camera. 2nd approach is optimization of 1st approach where we don't need to calculate the level order traversal and you have explained that in the an amazing way with dfs. 3rd approach is just fire :) Thanks khushbu for the solution.
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 жыл бұрын
Thanks
@saitama_capedbaldy9758
@saitama_capedbaldy9758 3 жыл бұрын
Awesome explanation, and i am lucky to find this channel.
@schan263
@schan263 8 ай бұрын
Thanks for providing multiple solutions and the explanation was clear.
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 8 ай бұрын
Thank you!!! 😊
@NiteshKumar-do4en
@NiteshKumar-do4en 2 жыл бұрын
parent == null should only be true for one time (root node case) then answer is always one , i don't understand
@arghyapal8439
@arghyapal8439 2 жыл бұрын
In approach 1, how/why do you assume that root will be covered to start the solution? In approach 2, when you start from leaf level, why do you assume that leaves will be covered? Most important part is , explaining how do you reach some assumption with certain examples.
@lohitpoojary5053
@lohitpoojary5053 Жыл бұрын
Top class explanation and solution....Keep it up✌✌
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy Жыл бұрын
Thanks a lot 😊
@sakanademon777
@sakanademon777 2 жыл бұрын
Can I ask why left and right can equal to 0 in a DFS fucntion where the base case is set to " if node == null, return 1?"
@nate-nf9sv
@nate-nf9sv 3 жыл бұрын
I get a similar solution from a blog, but it didn't explain so much. This video is helpful, thank you!
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 жыл бұрын
Glad to hear that !!
@Jay-lj2bv
@Jay-lj2bv 2 жыл бұрын
Beautiful explanation thanks!
@TheEdwinpako
@TheEdwinpako 3 ай бұрын
I feel like this there’s counter case for the algorithm Take the same tree as in video. Remove right child of the root On new tree algorithm would still give 3, while correct answer is 2
@vivekhattarge5795
@vivekhattarge5795 3 жыл бұрын
Hey, Thanks a lot for these videos. Nice explanation. The graphical explanation you put here is very helpful.
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 жыл бұрын
Glad you like it !!!
@abhishekkrishna9757
@abhishekkrishna9757 3 жыл бұрын
Very well explained! Thanks Could you please make a video on min. taps required to whole garden.
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 жыл бұрын
Thanks
@asmitamhetre
@asmitamhetre Ай бұрын
I was thinking the same but i was unable to figure out how i could find covered node in short i was unable to think set data structure !
@abhijitbiradar
@abhijitbiradar Жыл бұрын
greate video, appreciate your efforts. Thanks
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy Жыл бұрын
Thanks Abhijit for the appreciation.
@dcauz
@dcauz 2 жыл бұрын
Let the leaf nodes be at level 1, their parents are at level 2, and so on. Then you should only need cameras at levels n%3 + 2. ie. every 3rd level. All of the examples are at every other level. However, this results in the odd levels (other then the leaf nodes) being covered by two cameras, which is not neccessary.
@___vandanagupta___
@___vandanagupta___ 2 жыл бұрын
Amazing solution!!!!!!
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 2 жыл бұрын
Thank you so much!!
@knimr3
@knimr3 2 жыл бұрын
Thanks!
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy Жыл бұрын
👌👌
@udaykumar555
@udaykumar555 3 жыл бұрын
Hi khusboo, Can we have a level order traversal and get the count for alternate levels which is minimum ?
@soumyadiptabanerjee8256
@soumyadiptabanerjee8256 3 жыл бұрын
Can you please tell how did u get the intution ?
@rupakkorde
@rupakkorde 3 жыл бұрын
I get the intuition by solving a lot of test cases on paper
@soumyadiptabanerjee8256
@soumyadiptabanerjee8256 3 жыл бұрын
@@rupakkorde How did you understand that you should start from the bottom ?
@rupakkorde
@rupakkorde 3 жыл бұрын
@@soumyadiptabanerjee8256 I started filling cameras from top and found that camera at leaf node is covering less nodes
@soumyadiptabanerjee8256
@soumyadiptabanerjee8256 3 жыл бұрын
@@rupakkorde Thanks. And how did u decide that there will be three states ? What i was thinking whether to place or not place, so was getting 2 states.
@rajsharma6599
@rajsharma6599 2 жыл бұрын
in the set solution wht time complexity is not O(nlogn) wea re searchimg each element in the set also right
@ragingpahadi
@ragingpahadi 3 жыл бұрын
This was awesome. Now second solution is entrenched in my mind !
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 жыл бұрын
Great to hear that !! Thanks
@pranovkumar7787
@pranovkumar7787 3 жыл бұрын
Hey i have one doubt. In the second approach , a leaf node will always return 0 , and hence the parent to leaf node will always attach a camera. Now that seems problematic , because it isnt really placing the camera at the right position , though it is able to calculate the min number of camera's. But it isnt actually placing the camera at the right place. Especially in the 2nd case of your example.
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 жыл бұрын
In the case of leaf nodes, its child(null node) will return 1. And as the child is returning 1, the leaf node will return 0 that is, no camera. Moving up, the level before the leaf will have the camera installed. Hope this helps !!
@pranovkumar7787
@pranovkumar7787 3 жыл бұрын
@@AlgorithmsMadeEasy Right , But in the 2nd example of Tree that you took(4:25). There we are supposed add a camera on the left most leafNode, But in the code we will never add a camera to the leaf node, isnt it contradicting ?
@harifrahman9925
@harifrahman9925 3 жыл бұрын
Solution with great intuition
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 жыл бұрын
Thanks !!
@akashhiremath4131
@akashhiremath4131 3 жыл бұрын
Hey, been following your channel for a while...Really nice and usefull....please upload the solutions of leetcode contests as well...... :)
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 жыл бұрын
Thanks !! We will try to put solutions for it.
@rahulgheware5752
@rahulgheware5752 Жыл бұрын
How can be parent==null condition to add camera on node
@RupinderSingh-gs8hz
@RupinderSingh-gs8hz 3 жыл бұрын
That's why I like this channel
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 жыл бұрын
Thanks 😀
@AviatorBro
@AviatorBro 3 жыл бұрын
once again thanks for such a beautiful explanation, I wish it was in Hinglish language, I would not have to slow down video speed at some places to understand it😅
@zaid.1271
@zaid.1271 3 жыл бұрын
im confused on why the parent has to be null?? if its null then how did u get to it? am I missing something?
@zaid.1271
@zaid.1271 3 жыл бұрын
ohhh the parent == null is for the root I think I understand now.
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 жыл бұрын
Yes 👍.
@rahulgheware5752
@rahulgheware5752 Жыл бұрын
But then the ans is always going to be one
@rahulgheware5752
@rahulgheware5752 Жыл бұрын
Because due to and operator the second conditions not executed
@anamariaaguilarcahuana9417
@anamariaaguilarcahuana9417 3 жыл бұрын
Nice explained, i've been watching some of your videos and always say time complexity, How do you calculate it? I am justo 17 years old
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 жыл бұрын
Thanks Ana, Just read about its basics and practice it on a few code snippets. You will be great after it !!
@lucasjackson7647
@lucasjackson7647 3 жыл бұрын
Lookup big 0 notation, gayle laakmann mcdowell explains it well
@risingstar7881
@risingstar7881 2 жыл бұрын
Disappointing👎
Merge Two Binary Trees | Live Coding with Explanation | Leetcode - 617
25:53
Algorithms Made Easy
Рет қаралды 6 М.
Distribute Coins in Binary Tree - Leetcode 979 - Python
17:41
NeetCodeIO
Рет қаралды 17 М.
Happy birthday to you by Secret Vlog
00:12
Secret Vlog
Рет қаралды 6 МЛН
БУ, ИСПУГАЛСЯ?? #shorts
00:22
Паша Осадчий
Рет қаралды 2,7 МЛН
Prefix and Suffix Search | Live Coding with Explanation | Leetcode - 745
18:46
Algorithms Made Easy
Рет қаралды 10 М.
Binary Tree Cameras | Leetcode | DP on Trees
19:37
Kartik Arora
Рет қаралды 13 М.
Candy | Live Coding with Explanation | Leetcode -135
18:09
Algorithms Made Easy
Рет қаралды 14 М.
3 Types of Algorithms Every Programmer Needs to Know
13:12
ForrestKnight
Рет қаралды 498 М.
979. Distribute Coins in Binary Tree | Tricky DFS | Recursion
17:24
Aryan Mittal
Рет қаралды 4,6 М.
Binary Lifting (Kth Ancestor of a Tree Node)
18:01
Errichto Algorithms
Рет қаралды 100 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 565 М.
Happy birthday to you by Secret Vlog
00:12
Secret Vlog
Рет қаралды 6 МЛН