Friday, May 1, 2020

Case study: Lowest common ancestor

May 1, 2020

Introduction


It is the first interview I got the whole week. I worried about interviewing.io financial situation, and free anonymous interview is no longer affordable since some one has to pay the bill. A lot of layoffs last two months, people are flooding in job market for software engineer positions.

Mock interview case study



Here is the code.





Discussion we had on the mock interview:

The clever part is to return two things in recursive function. One is to find lowest common ancestor, if it is found then it should be returned; Second one is supporting role to calculate the node found. As we know, the node can be root node or any child node in binary tree. Using total nodes found is the technique to make it easy to identify the edge case: root node is one of nodes p or q, then another node is in subtree nodes.

One thing to make it more readable is to replace checking of return TreeNode null with node's count comparison to value 2 instead.

Interviewer feedback


Interviewee - an ex-facebook engineer



His second algorithm is also bug-free, here is the link.

Actionable items


May 25, 2020

The interviewee is young and top talent engineer. After the mock interview, he saw my feedback, and then he decided to get connected on interviewing.io. I should ask a linkedin.com connection from him, so I can track his career success later on.

No comments:

Post a Comment