Binary Tree Cameras | Leetcode 968 | Recursion

preview_player
Показать описание
Time Complexity : O(n) where n is number of nodes in binary tree
Space Complexity : O(h) where h is height of binary tree


Please like, share and subscribe if you found the video useful. Feel free to ask in comments section if you have any doubts. :)

#DataStructuresAndAlgorithms
#LoveBabbarDSASheet
#interviewpreparation
#AyushiSharma
Binary Tree Cameras solution
Binary Tree Cameras Leetcode
Binary Tree Cameras C++
Binary Tree Cameras Java
Binary Tree Cameras Python

🔥🔥🔥🔥👇👇👇

Checkout the series: 🔥🔥🔥
LIKE | SHARE | SUBSCRIBE 🔥🔥😊
Рекомендации по теме
Комментарии
Автор

Thanks, Did it!

Guys do handle one edge case when we only have 1 node....

// Lets have three states at each node
// 2 = Node is holding an camera
// 1 = Node covered by an camera
// 0 = No coverage
var minCameraCover = function(root) {
let cameras = 0;
function solve(node) {
if (!node) return 1;

let left = solve(node.left);
let right = solve(node.right);

if (left === 0 || right === 0) { // child not covered, we need camera (2)
cameras++;
return 2;
}
if (left === 1 && right === 1) { // Both child are covered, but we are not (0)
return 0;
}
if (left === 2 || right === 2) { // one of child is having camera we are covered (1)
return 1;
}
}

let isRootNotCovered = solve(root) === 0;
return isRootNotCovered ? cameras + 1 : cameras;
};

Shubham-ycnz
Автор

spent whole day on this question. Thanks for clearing it!

sidharthsinghdhanda
Автор

Ayushi u've got nice convincing skills
n explanation skills
thanks for making it simple!

sagarbora
Автор

Real Time Interview Experience with this question in DE SHAW - _ - . Not selected because of this... Feeling Regret !!

monstercoder
Автор

Amazing explanation. Was stuck for a long time but now it's clear 👍🏻

pranavpatki
Автор

Worth it to watch 20 min video!! Hence subscribed..

aatiqafzal
Автор

It's as simple as that. Loved your explanation <3

phoenix__
Автор

Hi Aayushi I have Managerial round of interview for Walmart software Engineer profile what shall I prepare and how to crack it.

ruchikabhandari
Автор

Loved the explanation ...solved it already using dp but it was lengthy...btw thanks for such a simple and concise explanation

KuldeepKumar-kicu
Автор

I want to learn data structure through java from where I have to start please suggest

somyagupta
Автор

Best Explanation for this particular problem. Thank You

abhayagarwal
Автор

Extremely neat and well represented solution. well done!!

anandchowdhury
Автор

Thank you so much for doing your videos in english. Your explanations are too good! We south indians also exist. So bummed out seeing all the good content in Hindi!!

sharmilat
Автор

Im always stuck at the hard problems, am able to solve medium most of the times . Any advice for tacking hard problems ?

shashanksingh
Автор

How u came up with this solution? Bcoz its not very intuitive at first.. First thing that comes to mind is DP (place and dont place camera).
But great solution and explanation

Ajay-cvzs
Автор

Can you post java solution for the same approach?

rohanpal
Автор

I thought that there could be a formula using number of nodes .

shivamnegi
Автор

Perfect!
Hope to see you in Walmart soon.

AshishMishra-ctiy
Автор

Damn your explanation is soo good as always :)

manaskumarpanda
Автор

How did you upload Leetcode solution on githhub ?

harshitsaini
visit shbcf.ru