Ready for your dream job?

Welcome to the most accessible guide to technical interviews. Here's a preview of how the platform will look.

We believe that technical interviews are a matter of practicing well. We've referenced hundreds of resources on habit change, education design, and algorithms to design the best and most streamlined learning experience.

Subscribe now


September 19, 2020

“Information is useless if it is not applied to something important or if you will forget it before you have a chance to apply it.”

- Tim Ferriss

Day 9: Lowest Common Ancestor

You're given a binary search tree and two of its child nodes as parameters. Can you write a method lowestCommonAncestor(root: Node, node1: Node, node2: Node) to identify the lowest common ancestor of the two nodes? The lowest common ancestor is the deepest node that has both of the two nodes as descendants.

In the below example, the lowest common ancestor of node 5 and 8 is 7.

      / \
     4   8
    / \
   1   5

The method will called in the following manner: lowestCommonAncestor(root, node1, node2);.

You can assume our standard node definition for the tree vertices:

function Node(val) {
  this.val = val;
  this.left = this.right = null;
Have you seen this question before? We are frequently adding problems and may have updated the order. You can change the day that you're on in the settings panel.

Click to solve →

As always, you can see the solution and a full step by step explanation at this link.

Want a Free Month of Premium?

We are always trying to make the platform better. We'd like to chat with users who'd like to help us improve the site!

We're looking to recruit roughly 5-10 users to have a conversation with our Product team. These conversations will last roughly half an hour, and will mostly be around your goals, how you use AlgoDaily, and what you'd like to see. In return, users will receive a full month of AlgoDaily Premium. If interested, please directly respond to this email with your name and availabilities in the next few weeks.

The Full AlgoDaily Course - On Sale!

AlgoDaily's technical interview course gets results!

Love the daily emails? AlgoDaily exists to provide high quality coding interview prep and career resources to developers from non-traditional paths. In the course, you'll find:

One last thing-- if you liked this email, and found value in it, could you kindly forward it to a friend who might benefit?

Our mission is to make tough technical interviews accessible to all, especially those from non-traditional CS backgrounds. I'd deeply appreciate your help in spreading the word!


Sign up for our newsletter list and join over 10,848 brilliant developers leveling up and solving coding challenges daily.

Preview now

Back Terms and Conditions