Here's a sample AlgoDaily newsletter.

You can sign up for it at the bottom of this page.

ALGODAILY

September 22, 2021

“I believe in, "You don’t ask, you don’t get.”

- Carla Harris


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.

/*
       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;
}

Constraints

  • Number of nodes in the BST <= 1000
  • The nodes will always contain integer values between -1000000000 and 1000000000
  • Expected time complexity : O(n)
  • Expected space complexity : O(1)

Get the Solution →

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. As always, you can see the solution and a full step by step explanation at this link.


Love the daily emails? AlgoDaily exists to provide hand-held coding interview coaching and career resources to developers from non-traditional paths. With premium, now on sale, 50% off, you'll get:

  • Unlimited access to all courses and materials
  • Customize your AlgoDaily newsletter by switching to Systems Design Daily or another crash course newsletter, and choosing the day you're on
  • Access to 400+ lessons and challenges, 1000+ diagrams and illustrations, 400+ quizzes, and 10+ hours of video
  • At least one new career building course added monthly
  • Bulk export all of your completed solutions, access the notes tool, track job applications, and see all community submissions
  • 100% advertisement free
  • Bonus: PDF, Mobi, and ePub copies of The AlgoDaily Book: Core Essentials (a $29 value)

Get Premium Today →


Hands Down the Best Systems Design Resource?

I was perusing Hacker News last week when I encountered a link subtlely titled "System Design Interview Book Review". Curious, I checked out the article-- it was a review of a resource I'd never heard of called, "System Design Interview: an Insider's Guide".

I was floored by this review! The following are quotes directly from the article:

"...the most "real-world" systems design book I've come across that does a solid effort to teach concepts, step by step, to people who have yet to work at systems at scale..."

"...a solid recommend from me: and not just for preparing for the systems design interview, but to strengthen your systems design muscle for the day-to-day."

Now, this was written by an engineer who's worked at Uber, Skype, and JP Morgan. All those companies maintain some serious, mission critical, large-scale software systems. If he says it's a good read, you'd better believe it.

I checked the course out and found it to be the perfect compliment to AlgoDaily. The same way we focus our learning around problems, Systems Design Interview focuses on real world use cases. What I love is the systems covered include ones you'll likely build as a software engineer in 2021: a web crawler, news feed, autocomplete, Google Drive, key-value store, etc.

Check out "System Design Interview: an Insider's Guide" today! I highly recommend it.


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!

Thanks,
Jake

Like the above? Try us for free.

We'll send you 100+ of the most common coding interview questions, once a day with visual explanations. Join over 25,323 users who are doubling their salaries in 30 minutes a day. All subscribers also get an 86-page interview fundamentals PDF and a week of lessons for free.