Friday, July 27, 2018

Leetcode 687: Longest univalue path - recursive design learning

July 27, 2018

Introduction


It is an easy level tree algorithm. I spent over 60 minutes to write and learned from other shared source code. It is very interested algorithm and I like to learn.


My learning


I chose one of the discussion and write my C# practice here.


Follow up 


7/28/2018 10:22 PM

One thing I can do is to go over the example, and walk through the example, give the explanation of the recursive function design. Also try to explain the algorithm using less than 5 minutes.

       5
    /      \
   4       5
 /   \        \
1   1        5

The idea is to traverse the tree using preorder, visit each node once. I think that it is very good practice to explain how to design a recursive function to count how many nodes from the root node to have same value continuously to leaf node.

Follow up 


August 1, 2018

I continuously used the algorithm to give the interviewee to work on one more than two times. Both of them had difficult time to come out the clean solution in less than 45 minutes. One of them has issue to work on recursive function and design the recursive function on the value cross the root of tree.

I was asked why I spend my time to work on interview, help others to prepare and learn. I explained to the peer that I also learned from his performance. When he asked me what to recurse on, if left side path or right side path, actually it is maximum of left side path and right side path. I could not tell the answer right away. I know that I just memorize the study code, I really have to give myself time to review and think and come out fully understanding as well.

I shared my thoughts with interviewee, there are hundreds of solution for this tree problem. I could not verify every line of code for you. But I did challenge you the design of recursive function is basically wrong. You cannot recurse on something cross the root node.

So good experience to be an mock interviewer on interviewing.io. It helps me to learn the algorithm I just practice. If I do speak out my mind, the interviewee did agree with me.

Sometimes it is hard for me to give feedback honestly, since the peer may be under pressure to try to get startup interviews. The feedback is important for them as well.

No comments:

Post a Comment