Looking to make a Q&A video soon! Follow me on Instagram and shoot me a DM with your question if you're interested in participating!!! instagram.com/kevinnaughtonjr/
Just wondering.. how many attempts or how much time did it take you to initially solve these problems? I am still getting up to speed myself for some interviews, and it takes me a long time to figure out some of these. Love the videos and explanations.
@@KevinNaughtonJr If you have the time, could you go over the Maximal Square (leetcode.com/problems/maximal-square/ ) problem? I've read the leetcode article for the solution, but it's a bit confusing imo
Super helpful video, I attempted this problem before watching and kind of pidgeon holed myself by checking vals on the way down as opposed to bottom up. Any advice on how to have the intuition when something will be bottom up/top down with regards to tree recursion (or is it safe to assume we'll probably always want a bottom up approach?).
Would it be more consistent in the main function instead of checking for if (!toDelete.contains(root.val)) {...} - check the return value of removeNodes(), and if it's NULL - add the root? Of course that'll fail if we got root==null as an argument, so an additional check for that will be needed. But it'll be needed in the current implementation as well.
Thank you! If you find my explanations helpful be sure to sign up for the interviewing service I created thedailybyte.dev/?ref=kevin I'd recommend joining the annual tier if you can!
For the top-bottom approach, can't you just "save what your left and right sub trees are before removing the root? This way, you won't lose the reference to them... could you explain why this doesn't work?
You deserve to be rich with CZcams money, hopefully you'll find sponsors and a boom in channel viewers. You are a better teacher than most of my teacher in college
Cool video,as always !! Bruh,find a way to popularize your channel cause it has good content and is of great help to computer science students like me.
Hi Kevin, how come we return null (above the return root) instead of appending it to remain? I tried it out, doesnt work - but I can't explain it - we arent ever calling append on the null value
Since we are adding only left or right node to the remaining array , how will the sub array be created it the final result should be an array of nodes or roots not an array of sub arrays. I would like to know how the sub arrays were created
The return type for the removeNode(...) method should be TreeNode and not void. I am not sure how it compiled and executed successfully for you?? Or did I miss something?
Arindrajit Seal thanks! If you need help with interview prep be sure to subscribe to the interviewing service I created, The Daily Byte! I recommend joining the annual plan thedailybyte.dev/
Everything good I just do not think you should call in line 18 the function removeNodes that returns a TreeNode without having an object that receives it. I know Java garbage collection will destroy it, but I think it is bad practice
Yo I solved it the same way! Verbatim almost! Putting up a python implementation here for anyone else going through the LC google tagged problems! ``` class Solution: def delNodes(self, root: Optional[TreeNode], to_delete: List[int]) -> List[TreeNode]: to_delete = set(to_delete) ans = [] def delete(node): if not node: return None node.left = delete(node.left) node.right = delete(node.right) #if we need to delte if node.val in to_delete: #if there is a left, we want it to be a part of the first if node.left: ans.append(node.left) if node.right: ans.append(node.right) #we need to delete this node that we are one return None return node delete(root) #check root if root.val not in to_delete: ans.append(root) return ans ```
Looking to make a Q&A video soon! Follow me on Instagram and shoot me a DM with your question if you're interested in participating!!!
instagram.com/kevinnaughtonjr/
Just wondering.. how many attempts or how much time did it take you to initially solve these problems? I am still getting up to speed myself for some interviews, and it takes me a long time to figure out some of these. Love the videos and explanations.
These videos are incredibly helpful, really appreciate the way you walk through the problem instead of just diving into the code.
Abdulrahman Tolba anytime!
@@KevinNaughtonJr If you have the time, could you go over the Maximal Square (leetcode.com/problems/maximal-square/ ) problem? I've read the leetcode article for the solution, but it's a bit confusing imo
The best explanation I could find on CZcams about this problem. Thank you!
Thank you Kevin. This is very neat! I was able to solve the question in Python after watching your explanation and demo. Thanks again!
Super helpful video, I attempted this problem before watching and kind of pidgeon holed myself by checking vals on the way down as opposed to bottom up. Any advice on how to have the intuition when something will be bottom up/top down with regards to tree recursion (or is it safe to assume we'll probably always want a bottom up approach?).
Hey Kevin, could you do questions on dynamic programming. Thank you.
good way to teach the concept of bottom up tree processing with recursive DFS. haven't come across many of these problems yet. thanks, Kevin
anytime Jonathan :)
Amazing! I forgot to like and comment, so i came back to do it... Your content is full of learning and each line you speak weighs..
Ankit Agarwal you’re the best thanks so much!
Hey thanks for the work on these videos. Do you have a list of all of the popular questions?
I like the simple explanation. Good job.
you are the big homie. thanks for another great vid.
Nice Explanation! So I'm new to this, could you tell me if this bottom up-approach is what is known as back-tracking?
Would it be more consistent in the main function instead of checking for if (!toDelete.contains(root.val)) {...} - check the return value of removeNodes(), and if it's NULL - add the root? Of course that'll fail if we got root==null as an argument, so an additional check for that will be needed. But it'll be needed in the current implementation as well.
Is this similar to deleting nodes in a heap (max or min) or what makes this different from deleting nodes from heap ?
Thanks for the amazing explanation!
Did not expect that drop at the beginning lmao
yeah it's random af
Hey Kevin, I was wondering how is it making List inside the ArrayList?
Amazing explaination...your videos are really very helpful...
Thank you! If you find my explanations helpful be sure to sign up for the interviewing service I created thedailybyte.dev/?ref=kevin I'd recommend joining the annual tier if you can!
Great video! Thanks! (:
For the top-bottom approach, can't you just "save what your left and right sub trees are before removing the root? This way, you won't lose the reference to them... could you explain why this doesn't work?
bottom-up approach hint really clicked. thanks kevin!
dm anytime! If you need help with interview prep be sure to subscribe to The Daily Byte! thedailybyte.dev/
Hi Kevin, I just help your help as I got a rejection in the interview. Can you please tell me how to reach you out ?
You deserve to be rich with CZcams money, hopefully you'll find sponsors and a boom in channel viewers.
You are a better teacher than most of my teacher in college
Thanks Adrian hopefully the channel keeps growing :)
Cool video,as always !!
Bruh,find a way to popularize your channel cause it has good content and is of great help to computer science students like me.
Killing it!
Google questions are so ambiguous and tricky, though solutions can be so simple if understood properly.
Hi Kevin, how come we return null (above the return root) instead of appending it to remain? I tried it out, doesnt work - but I can't explain it - we arent ever calling append on the null value
you know, you can also do root = removeNodes(root ...); then check (if root != null) {add to remaining}
Hi Kevin, I think you have not posted any videos regarding binary search an array type of questions. Request to upload some.
Thanks Kevin
good one.
Amazing solution!
Since we are adding only left or right node to the remaining array , how will the sub array be created it the final result should be an array of nodes or roots not an array of sub arrays. I would like to know how the sub arrays were
created
Hi Kevin. I like your background music, could you please tell who is playing?
check the description of the video!
great kevin
Could a BFS also work?
The return type for the removeNode(...) method should be TreeNode and not void. I am not sure how it compiled and executed successfully for you?? Or did I miss something?
Even I thought of same but he corrected it before submitting...
Do we really need to delete the node? We just have to return remaining nodes from tree if given nodes were deleted.
The return type of removeNode should be TreeNode.
Ty,kevin
You should return to the forest.
Why you never try to run code and just submit it directly after writing
thanks
I did the same in the first attempt!
void , you cannot return type
You Write code so beautifully.
thank you :')
Why is the space complexity O(N)? Shouldn't it be more?
You wayyyyyy overcomplicated this.
Thank you,
Please upload the solution for house robber 3 .
class Solution {
public int findMax(TreeNode root, boolean rob) {
if(root == null)
return 0;
if(rob)
return root.val + findMax(root.left, !rob) + findMax(root.right, !rob);
else
return Integer.max(findMax(root.left, !rob), findMax(root.left, rob)) + Integer.max(findMax(root.right, !rob), findMax(root.right, rob));
}
public int rob(TreeNode root) {
int option1 = findMax(root, true);
int option2 = findMax(root, false);
return Integer.max(option1, option2);
}
}
class Solution {
Map map = new HashMap();
public int rob(TreeNode root) {
if(root == null) return 0;
if(map.get(root) != null) return map.get(root);
int total = 0;
if(root.left != null){
total += rob(root.left.left) + rob(root.left.right);
}
if(root.right != null){
total += rob(root.right.left) + rob(root.right.right);
}
int ans = Math.max(root.val + total, rob(root.left) + rob(root.right));
map.put(root, ans);
return ans;
}
}
Just one word: wow
You are pretty awesome
Arindrajit Seal thanks! If you need help with interview prep be sure to subscribe to the interviewing service I created, The Daily Byte! I recommend joining the annual plan thedailybyte.dev/
@@KevinNaughtonJr okay will look into it
thanks kev
Faraz anytime Faraz!
DFS is a more generic term. I would call it post order traversal
Why do you directly hit the "Submit" button, why not try "Run Code" first :P Jokes, thanks for yet another learning.
Everything good I just do not think you should call in line 18 the function removeNodes that returns a TreeNode without having an object that receives it. I know Java garbage collection will destroy it, but I think it is bad practice
Its more like Post order traversal not DFS
You’re pretty
Make another video with me Car!!!
Yo I solved it the same way! Verbatim almost! Putting up a python implementation here for anyone else going through the LC google tagged problems!
```
class Solution:
def delNodes(self, root: Optional[TreeNode], to_delete: List[int]) -> List[TreeNode]:
to_delete = set(to_delete)
ans = []
def delete(node):
if not node:
return None
node.left = delete(node.left)
node.right = delete(node.right)
#if we need to delte
if node.val in to_delete:
#if there is a left, we want it to be a part of the first
if node.left:
ans.append(node.left)
if node.right:
ans.append(node.right)
#we need to delete this node that we are one
return None
return node
delete(root)
#check root
if root.val not in to_delete:
ans.append(root)
return ans
```