Hey Kevin, your videos are really helpful with interview prep! For this question, I felt an in-order traversal within the bounds L & R to be more intuitive than a BFS, just because it takes advantage of the fact that the tree is a BST.
@asimansubera9605 жыл бұрын
Hello Kevin, Hope you are doing well! I am following your all LeetCode interview videos. Thank you for helping and educating me with your ideas and thought process solving each problem. These are very helpful.I would like to have a different video(s) from you with a holistic view of any interview question covering following aspects: 1. how you approach any problem 2. when to use Queue vs stack vs hashmap vs hashset vs arraylist, linkedlist, iterative vs recursion vs DP etc. 3. when to use one data structure vs multiple data structures 4. When to use an additional tracking data structure 5. when to use binary search when question is not about search though 6. when to use two indexes from both end of array I know it would be difficult to cover everything in a single video. You may create series of videos on this. Thanks in advance! -AB
@gideonkibetcheruiyot75005 жыл бұрын
your music is my favorite part of your videos, Kevin. Keep up the great work.
@KevinNaughtonJr5 жыл бұрын
Gideon Kibet Cheruiyot thanks Gideon I really appreciate it!
@jasonfong25825 жыл бұрын
Any idea what the music is? Seems familiar
@crimsoncad32304 жыл бұрын
Why can't we use Tree traversal algorithm like in-order traversal which will travel all the nodes ???
@ayushkashyap82994 жыл бұрын
because there is a more efficient way of doing this. In which we don't have to traverse all nodes
@AnshumanKumar0074 жыл бұрын
@@ayushkashyap8299 we don't need to. We can check root.left if current.left > L and don't do it if it's not. We can do the same for root.right
@Tlacoyo59a4 жыл бұрын
I agree
@perpendicular3553 жыл бұрын
@@Tlacoyo59a Space complexity would be O(N) in case we do recursive in order traversal.
@gerryramosftw5 жыл бұрын
amazing bro, really appreciate this video. will be watching more and probably all! glad I found your channel
@KevinNaughtonJr5 жыл бұрын
Anytime and thanks Gerard I appreciate the support!
@stevenanthony40945 жыл бұрын
Hey Kevin, just wanted to say a quick thank you, your simple explanations have helped me tremendously.
@anushree37445 жыл бұрын
Did not get why we didn't opt for DFS but BFS....
@leanobajio5 жыл бұрын
The choice is arbitrary. I would have used DFS since it doesn't need a queue to implement, so it uses less space.
@anushree37445 жыл бұрын
@@leanobajio exactly
@KevinNaughtonJr5 жыл бұрын
You can use either but bfs avoids using recursion which I think generally scales better (with dfs if you have a really large tree, you could run into a stack overflow)
@KevinNaughtonJr5 жыл бұрын
Dean careful because dfs still uses extra space because of the recursive calls on the stack!
@leanobajio5 жыл бұрын
@@KevinNaughtonJr Oh yeah! I completely forgot about that.
@satrap2997924584 жыл бұрын
Your music playlist is dope
@shivamsachan51095 жыл бұрын
can you explain the initialization of queue? (TreeNode & LinkedList)
@KevinNaughtonJr5 жыл бұрын
SHIVAM SACHAN we wanted to make sure we store tree nodes in our queue so that inside our while loop we can have references to the current node’s children (we couldn’t do that if we stored something like integers in our queue) and linked list is just how you initialize queues in java (under the hood a queue is just a linked list with certain properties/abilities)
@lizdenhup4 жыл бұрын
Thank you for making such an awesome video!! So clear! One question --why are you not making the condition on lines 24 and 27 greater than or equal to/less than or equal to, if the range is inclusive? Thanks. :)
@bhanuarora45042 жыл бұрын
can we solve this problem in O(logN)?
@aditya2345674 жыл бұрын
Nice but what's the point in tree being binary search tree. Interviewer would expect you to use that property!
@saurabhprasad22954 жыл бұрын
Queue queue1 = new LinkedList(); The compiler saying.... its not declared in the scope.... please help....
@madiyar80795 жыл бұрын
More DP please!
@KevinNaughtonJr5 жыл бұрын
Madiyar Kaskabayev you got it! I’ll try to do more dp problems thanks for the input!
@mdzikrullah95754 жыл бұрын
Thank you for this video
@AmolGautam3 жыл бұрын
Thank you so much for the videos.
@hichemrehouma56165 жыл бұрын
Hey Kevin! Loving your videos! I just got off an onsite with Amazon and wanted to share a problem that I thought would be a good addition to your list. The problem says you have a list of arrays with 2 elements each, with first element being the name of the commander of the second element. Return a list with the names ordered by their rank from highest ranking to lowest ranking. I actually struggled a lot haha Lemme know your thoughts!
@ijaz20205 жыл бұрын
this is called topological sorting. google about it.
@naveenrawat62785 жыл бұрын
Topological sort does the trick.
@TonyDiCroce2 жыл бұрын
I'm curious why you didn't do an in order traversal? Then you could at least stop once Val is greater than R?
@MrSriravi5 жыл бұрын
Hey Kevin, thanks for your videos.Could you do a video on this problem "Permutation in String" LC-567.
@PatrickFong4 жыл бұрын
why do you check the current val of the TreeNode, before you add the left and right nodes? Shouldn't you check the left / right node that they are within the range?
@shaanyahoo3 жыл бұрын
why not DFS ?
@alexeydeynega76035 жыл бұрын
Can we use the information that this is binary search tree, and not just an arbitrary tree ? Maybe, this information will allow us to minimize number of nodes to be checked if we solve it recursively (not bfs)
@atift54655 жыл бұрын
Nice result and explanation! This is one of those fun problems that I found
@KevinNaughtonJr5 жыл бұрын
atif tirmizi thanks Atif as always I appreciate the support!
@contact2ck5 жыл бұрын
Kevin kindly explain 489. Robot Room Cleaner. Leetcode problem
@iloveallparties5 жыл бұрын
What does the average software engineering interview look like outside of companies like amazon, google, fb, etc? Do they all ask Leetcode?
@prageeth48555 жыл бұрын
For mobile dev positions specially 1. Ask to do a take home assignment or 2. Live coding of a component of an app.
@AndroidJames915 жыл бұрын
To add to the mobile dev position interviews, I just finished about 10 of them. Steps: 1. Usually a recruiter call to determine if you have the buzz words they want for the position 2. I'm seeing a lot of discussion with hiring manager or a lead engineer for the team in this step. Usually asking you to describe projects, work experience, how you work with others, difficult bugs you've solved, and to get a feel for what you're looking for tech stack/team wise and if you can speak the technical jargon. 3. 1:1 technical screen with an engineer. These were usually LeetCode easy questions OR paired coding exercise on an Android app OR take home coding test (Usually about four hours of time investment required) and a one hour discussion with an engineer to discuss decisions made. 4. On-site, which is about 3-5 hours depending on company. Technical round with design questions, technical round with algorithms questions, and cultural fit. Might also have a group round with engineers on the team to do an informal discussion/walkthrough through designing a component/feature for the app. Most companies won't ask you LeetCode hards like top companies will, but they will ask Easy to Medium level LC questions. They'll test your design skills, any knowledge that is necessary to do the job (mobile, for instance), and team fit. Source: I worked at Amazon for over three years and participated in the process of interviewing candidates. I've also done a number of technical interviews in the last four months. The process described may vary for more junior positions as I was interviewing for mid to senior level roles.
@saurabhprasad22954 жыл бұрын
superb man.... "You are the man"!!!!
@KevinNaughtonJr4 жыл бұрын
thanks Saurabh!!!
@ashishkmr5 жыл бұрын
Nice video, can you make more videos on leetcode hard/medium problems.
@KevinNaughtonJr5 жыл бұрын
ashish kumar thanks Ashish and yes I’ll see what I can do!
@nishadkumar73225 жыл бұрын
+Kevin Naughton Jr. Could you please showcase problem # 1248 on LC (Count Number of Nice Subarrays) when you find time?? Thanks man.
@rahulsinghai30335 жыл бұрын
Please solve some DP problem. I like your explanation
@KevinNaughtonJr5 жыл бұрын
rahul singhai thanks Rahul and you got it!
@jsxica37514 жыл бұрын
The videos that go over this in Python aren't as high quality as yours, any chance you will do some of these in Python?
@pawlstothewall3 жыл бұрын
I wrote a recursive solution in python just now (where node is the root node). Any constructive criticism appreciated. def range_sum_bst(node, mini, maxi): if not node: return 0 if mini
@sanchitjain97453 жыл бұрын
Nice explanation... :)
@kmdr4 жыл бұрын
Hey Kevin, why don't we check these two conditions when adding the left and right child to the queue: 1. current.val < L 2. current.val > R ?
@JohnLee-ob3fo3 жыл бұрын
Definition of BST (Binary Search Tree) The left subtree of a node contains only nodes with keys lesser than the node’s key. The right subtree of a node contains only nodes with keys greater than the node’s key. The left and right subtree each must also be a binary search tree.
@abhishekverma59284 жыл бұрын
Hey kevin, Thanks for your channel.It is really helpful. I have 1 doubt while adding left or right node in Queue you wrote if(current.left != null && current.val > L){ queue.add(current.left) } I think it should be current.left.val if(current.left != null && current.left.val >= L){ queue.add(current.left) } Also don't we need to check the upper bound condition also if(current.left != null && current.left.val >= L && current.left.val in case if Tree root node is start with 50, then we need to look both L and R in Tree's left and right node. Please correct me if I am wrong anywhere.
@sarveshchavan43915 жыл бұрын
I live ur videos but just a suggestion if u can explain with diagram it will be really good!
@KevinNaughtonJr5 жыл бұрын
sarvesh chavan thanks Sarvesh! Diagrams can be tricky but I’ll see what I can do!
@fridaytechtalk24524 жыл бұрын
Recursive Solution: public int rangeSumBST(TreeNode root, int L, int R) { if (root == null) return 0; if (root.val < L) return rangeSumBST(root.right, L, R); if (root.val > R) return rangeSumBST(root.left, L, R); return root.val + rangeSumBST(root.right, L, R) + rangeSumBST(root.left, L, R); }
@Ajayhanand5 жыл бұрын
I guess this needs segement trees
@Ajayhanand5 жыл бұрын
oh sorry i read it as an array range sum query
@prakad975 жыл бұрын
Hi Kevin, A video suggestion Leetcode #273 Number to Words..pls do if possible
@tlj775 жыл бұрын
public int rangeSumBST(TreeNode root, int L, int R){ int res = 0; if(root==null) return 0; if(root.valR) return rangeSumBST(root.left); res+=root.val; return rangeSumBST(root.right)+rangeSumBST(root.left)+res; }
@prageeth48555 жыл бұрын
Tks Kevin! 💯 Love to do a mock interview with u 😊
@KevinNaughtonJr5 жыл бұрын
Prageeth Kumara anytime Prageeth! If you’re interested in a mock interview check out my Patreon page! The link is in the description!
@abhaytiwari64115 жыл бұрын
hey kevin 83 number like is done my me
@marcgarcia31315 жыл бұрын
Hi Kevin, I have a tech interview for Google slated for the second week of December and would _love_ to pick your brain. I saw the Patreon link, so I'm just writing to get your attention and response, thanks! :)