I currently moved past a few phone interviews and I wanted to say thank you for all the help from your videos! I appreciate the quick and concise explanations.
There are 2 more ways to solve it. 1. Do inorder traversal. It traverses the tree in sorted order. If it is not in sorted order, it is not valid bst 2. Bottom up. The current node, Left subtree and right subtree of each node should be valid bst
I don't think the first method works for inputs like [1,1] where the inorder traversal and the sorted list are both equal and yet it is not a valid BST.
Avinash Parasurampuram You can make approach one work for cases like [1,1] by checking for duplicates as well as the sorted ordering since duplicates are next to each other in the traversal order
Your voice and solutions are smart. But I would recommend if you can put an example or a walkthrough your code with some other visuals so it's easier to understand. Anyways thank you man, love your channel.
Kevin Murimi looking forward to that coffee :) best of luck!!! If you want additional help preparing check out my Patreon page www.patreon.com/KevinNaughtonJr
@@fionamatu4996 @Mehmet Firat I didn't land the gig coz I bottled the System Design Round. I interviewed at Twitter, Microsoft and some UK startup a week later and landed all three though.
Hi Kevin! fantastic video, it's helping me a lot! Could you help me understand why the time complexity is O(N) in lieu of O(2^n)? I am failing to see why. Thanks
It seems easy because you're being explained the method in a video as opposed to figuring it out yourself. There are a lot of nuisances with this one IMO
Hi Kevin, I'm a fan of your channel. Thanks a lot for all your quick videos. But I believe the below case is not covered here. ```Tree tree1 = new Tree(6); tree.left = new Tree(2); tree.right = new Tree(8); tree.left.left = new Tree(1); tree.left.right = new Tree(9);```
Because it is common to check for the left node and then the right node. In this case, max represented the max of the left so it goes first. Also thought about it.
This is a smart solution!!!☺👍👍but how about an inorder traversal that would store all the elements of a BST in sorted order?? if it's not strictly in sorted order return false.
you would use a depth first search or a breadth first search to validate the tree iteratively. you would more or less use the same conditional ideas as in the recursion solution but you would need to use it with a Queue or Stack data structure depending on which search you use.
Why can't we just do recursion inside of the original function instead of creating a helper function? Can't we just update the max to be root.right.val and min to be root.left.val every time?
instagram: instagram.com/kevinnaughtonjr/
twitter: instagram.com/kevinnaughtonjr/
I currently moved past a few phone interviews and I wanted to say thank you for all the help from your videos! I appreciate the quick and concise explanations.
There are 2 more ways to solve it.
1. Do inorder traversal. It traverses the tree in sorted order. If it is not in sorted order, it is not valid bst
2. Bottom up. The current node, Left subtree and right subtree of each node should be valid bst
I don't think the first method works for inputs like [1,1] where the inorder traversal and the sorted list are both equal and yet it is not a valid BST.
@@avinash9307 yup, i was going to say that, most places that mention that approach, mention it with caution
Avinash Parasurampuram You can make approach one work for cases like [1,1] by checking for duplicates as well as the sorted ordering since duplicates are next to each other in the traversal order
@@avinash9307 simply check that list[i] is greater than list[i-1] for i from 1 to length of list -1
Kevin great audio quality, thanks for making a clear and easy to understand video!
Thanks Kevin and anytime!
In C++ you would need to use `long` as the type of `min` and `max` in order to pass all Leetcode's test cases (so use `LONG_MIN` and `LONG_MAX`).
Your voice and solutions are smart. But I would recommend if you can put an example or a walkthrough your code with some other visuals so it's easier to understand.
Anyways thank you man, love your channel.
Nice content. Thanks for uploading.
Thanks and anytime!
Great explanation dude. Your videos are concise and your code is great. Keep up the good work🤘.
Kevin if I ace this Facebook onsite interview, I owe you a coffee bro! thanks
Kevin Murimi looking forward to that coffee :) best of luck!!! If you want additional help preparing check out my Patreon page www.patreon.com/KevinNaughtonJr
How did your interview go @Kevin?
how was the interview bro
@@fionamatu4996 @Mehmet Firat I didn't land the gig coz I bottled the System Design Round. I interviewed at Twitter, Microsoft and some UK startup a week later and landed all three though.
@@KevinNaughtonJr how can I buy you the coffee bro? I didn't land the Facebook one but I landed both Microsoft and Twitter :)
Thanks Kevin.
Hi Kevin! fantastic video, it's helping me a lot! Could you help me understand why the time complexity is O(N) in lieu of O(2^n)? I am failing to see why. Thanks
great solution! (this question really doesn't feel like a medium one, more of an easy in my opinion
Thanks!
It is a medium because in an interview they would only accept the in order traversal method. The other two methods are very verbose and messy.
It seems easy because you're being explained the method in a video as opposed to figuring it out yourself. There are a lot of nuisances with this one IMO
this is a great series and pls make more of these
and im also at nyu!!
thanks and NO WAY go violets/bobcats/whatever NYU is!!!!
Also from NYU here
Why INTEGER is used in place of int?
Amazing explanation brother
Awesome!!!
:)
Very well explained. Could you please post video for buy/sell stock problem I, II and III?
Skew tree is the word.
Well explained. Thank you
Doesn't work for->[0,null,-1]
i was looking for this comment
Awesome🔥
Thanks!
awesome explanation!
I hear brockhampton, i press like
Haha thanks Nurrizky :)
I like your solution, much better than mine.
thanks!
Thanks for these vids! They're super helpful. Do you have plans to do some of the harder leetcode questions sometime?
Anytime! And I’d be happy to take suggestions for other problems you want done if you have any!
@@KevinNaughtonJr Can you do some questions involving heaps?
Yaaay youre back~!
WOOOOO YEAH I'M BACK!!!!
What about for [0,null,-1]?
Hi Kevin, I'm a fan of your channel. Thanks a lot for all your quick videos. But I believe the below case is not covered here.
```Tree tree1 = new Tree(6);
tree.left = new Tree(2);
tree.right = new Tree(8);
tree.left.left = new Tree(1);
tree.left.right = new Tree(9);```
Hey Kevin. I'm a little confused on how the root being null would return true. wouldn't the root being null make the tree false?
Awesome (Y)
Thanks!
Look for all cases, forgot to valisate for max
I don't know why you put (root, max, min) instead of (root, min, max). it is confusing. anyway, thank you!
Because it is common to check for the left node and then the right node. In this case, max represented the max of the left so it goes first. Also thought about it.
This is a smart solution!!!☺👍👍but how about an inorder traversal that would store all the elements of a BST in sorted order?? if it's not strictly in sorted order return false.
Can you make a playlist of all the songs you have used in your intro ?
Nice video Kevin. Do we solve this using any loop without recursion?
you would use a depth first search or a breadth first search to validate the tree iteratively. you would more or less use the same conditional ideas as in the recursion solution but you would need to use it with a Queue or Stack data structure depending on which search you use.
Below scenario is not covered
/* 100
50 150
25 75 125 175*/
DFS is the way to go
oh yeah
two videos in two days? someone stop this man
YOU CAN'T STOP ME J
holy crap it took me so long to understand the last part. embarrassing
Why can't we just do recursion inside of the original function instead of creating a helper function? Can't we just update the max to be root.right.val and min to be root.left.val every time?
ruclips.net/video/LRXs-uNHVYQ/видео.html
pls try to explain with example, i didn't get the last one