Saturday, January 19, 2019

Case study: Longest univalue path mock interview

Jan. 19, 2019

Introduction


It is my mock interview and I had discussion with a young talent from a startup company in California. We worked together and wrote together a solution, but this morning I tested against Leetcode online judge, the code failed one test case, I could not figure out. I decide to move on now.

Case study


Here is my code gist.

Here is the code to read.


My analysis


Failed test case should return value 2, the code returns 5. So I have to figure out what is the possible reason for those extra values. 

I should add one more check, set left = 0 if there root.val does not equal to its left child's value. Same as right child's value.


No comments:

Post a Comment