Saturday, January 19, 2019

Case study: Longest univalue path mock interview

Jan. 19, 2019

Introduction


It is my mock interview again in Nov. 18, 2019 as an interviewer. I asked the interviewee to solve the longest univalue path. I like to do a case study on the interview.

Case study


I like to push myself to learn how to be a good interviewer. This time the interviewee wrote a solution with a bug, but I did not find the bug in the mock interview.

The interview was on Jan. 18, 2019.

Now it is Jan. 19, 9:54 AM. I put the idea into C# code and run Leetcode online judge. The code failed.

Here is the gist.

Uncover the problem


The problem is on the recursive to solve the cross path.

Line 35 return 2 + LongestUnivaluePath(root.left) + LongestUnivaluePath(root.right);

The counter example is the following:

Line 1:         3
Line 2:      /       \
Line 3      3        3
Line 4:   /   \
Line 5:  3    3

The above tree's longest univalue path is 3, not 4.

Actionable Item


I wrote an email to sam@interviewing.io and ask how I can modify my feedback.



No comments:

Post a Comment