Monday, June 1, 2020

case study: lowest common ancestor in binary tree algorithm

I like to write a short case study how good the interviewee is as a senior engineer in Microsoft with more than 7 years experience.

Case study

Here is the gist.

The interviewer wrote a working solution first, and I challenged him to solve edge case if p or q is not in binary tree, and then he added a function to check p is not binary tree and do some checking before LCA is found.

After that, I asked him to think about second idea to solve the problem; he wrote the idea using stack, after 10 minutes, I stepped in to ask him to find path from root to p and root to q first, using an example, two lists and then find LCA.

He wrote the algorithm.

Here is the gist.

I reviewed the code using binary tree with test case: Root node with value 1, left child with value 2, right child with value 3, p = node with value 3, find Root to p, [1, 3]. And his code works perfectly.




My feedback as an interviewer 



I shared my showcase with the link, and also the performance of ex-Facebook engineer. Here is the link.

No comments:

Post a Comment