Level: Intern
Round: Onsite · Type: Coding · Difficulty: 7/10 · Duration: 60 min · Interviewer: Unfriendly
Topics: Trees, Algorithms
Location: Mountain View, CA
Interview date: 2026-01-23
Question: Find the cheapest common ancestor for two nodes in a tree. Each node has a price and knows its parent and children. Given two nodes, find the common ancestor with the cheapest price. I discussed the brute force approach, coded it, and analyzed the time complexity. I also discussed test cases and edge cases, and mentioned optimal solutions when running out of time.
The coding question I received was:
Find the cheapest common ancestor for two nodes in a tree. Each node of the tree has a price and knows its parent and children. You are provided with two different nodes of the tree and you must find the one with the cheapest price among all the common ancestors.
I talked about a brute force approach, coded it out, and was asked about the TreeNode class setup, time complexity, dry run with an example, test cases / edge cases, and an optimal solution (but was out of time so I only discussed ideas and TC).