Thursday, January 31, 2019

Case study: 979. Distribute coins in binary tree

Jan. 31, 2019

Introduction


It is my mock interview lasting 100 minutes from 10:00 PM to 11:40 PM PST. I was so surprised since the interviewee is in eastern time zone, and start time is 1:00 AM EST. I like to write a case study on the mock interview

Case study


It is my favorite algorithm. I like to learn more about the algorithm through the mock interview. The interviewee has good education, very good communication skills, new graduate from top university, good job experience; I need to learn how to help and exchange ideas, make myself more helpful to contribute ideas.

We had very good discussion to explore the problem in depth after he solved the problem, tested the code with a test case.

I also review JavaScript programming language.

Here are interview in detail:
1. The discussion, ideas we discussed
2. JavaScript code with a test case
3. The discussion after the mock interview

I will come back with more detail.


Here is more...

One thing both of us learned in the discussion is how to calculate each edge in the tree once. We count the traffic to transfer coins through each edge. We like to count each edge once, the pseudo code above will count some edge more than once.

Interviewee feedback


Interviewer feedback


More discussion

I shared my experience in the contest of 120, I had problems to come out the optimal solution. Where to start? I thought about finding a node with zero coin first, and then I need to find a node with extra coins in the tree, but in order to get minimum coins, I cannot just find any node with extra coins. This makes the problem hard to solve.

Secondly, I have math undergraduate degree. I know that we have to prove that the optimal solution using post order bottom up is minimum value. How to prove it?

We had discussion and that is the reason we took extra time to explore those topics.

No comments:

Post a Comment