June 2019
It is an easy level tree algorithm. I got advice to work on easy level algorithm on Leetcode.com first in June 2018. So I started to work on all easy level tree algorithms on Leetcode.com in August 2018, I found out that my first practice was hard, and my idea did not lead to a working solution. After that, I asked the algorithm on interviewing.io as an interviewer, I continued to learn from every interviewee, and I like to put together a list of topics I learn through the experience. Here are the blogs I wrote based on my mock interview experience using this algorithm from August 2018 to June 2019. I will add some of practices here for me to master the tree algorithm.
August, 2018
My failed first practice, here is the link.
Recursive function design: return longest path from root to leaf instead
My first recursive solution, here is the link.
My first recursive solution, here is the link.
Case study two examples
Sept. 2018
Longest path cross the root, two case studies on example trees, the link is here.
Sept. 2018
Longest path cross the root, two case studies on example trees, the link is here.
Recursive function design: return cross root longest univalue path directly
Nov., 2018
One recursive function to solve the problem, here is the link.
Nov., 2018
One recursive function to solve the problem, here is the link.
Feb. 2019
check with parent node's value instead of check child's node - inverse check
C# post order - check with parent value with step by step illustration, here is the link.
C# post order - check with parent value with step by step illustration, here is the link.
Common mistakes in mock interviews:
- Make sure that every node is traversed, bottom up, post order traversal is most commonly used;
- Common mistake - visit left or right only if the root value equals to its left(right) child's value
So the whole tree will not be traversed properly. - Make sure that there is a place to increment one, otherwise the value will always be zero; explain to the interviewer, that one is related to which edge or node in example tree.
An experienced interviewer will check you a few things:
- post order traversal or preorder, bottom up or top down, what is your choice?
- How do you design recursive function, return directly asked or return indirectly?
- Count node or count edge?
- Do you check children node with two cases to discuss, or compare to parent node only one case?
- Argue the code will be correct.
A. Increment one check, relate to example tree edge or node clearly.
B. Make sure that all nodes will be traversed. Do not put conditional check for left or right child node's value to apply traverse; - Can you explain the algorithm very well? At least you warm up the traversal with an example, and then explain every node what will happen. Do not jump to coding for only solution you memorize. Click here to see how I explain the algorithm in case study.
Show case
I like to share my experience how I master a tree algorithm to work with over 50 most talent people in the world, every time 45 minutes discussion, and a lot of follow-up practice after mock interview as an interviewer. I do believe that it is possible for me to master a tree algorithm. I took time from August 2018 to June 2019 after my first failure practice dated on August 11, 2018.
Right now, I move on another tree algorithm called lowest common ancestor and ask the algorithm in mock interview on interviewing.io almost every time.
No comments:
Post a Comment