Solve tree and DP problems
AmazonSoftware Engineer · Technical ScreenLast updated
This pair of problems evaluates proficiency with tree data structures and traversal concepts (deepest shared ancestor) and with dynamic programming/state optimization on linear arrays (maximizing non-adjacent house values), assessing algorithmic reasoning, complexity awareness, and data-structure manipulation.
This coding round contained two algorithm questions:
-
Deepest shared ancestor in a binary tree You are given the root of a binary tree and two distinct nodes
pandqthat both exist in the tree. Return the deepest node that is an ancestor of bothpandq. A node may be considered an ancestor of itself. -
Maximize money from non-adjacent houses You are given an integer array
moneywheremoney[i]is the amount of money stored in theith house on a street. You may not take money from two adjacent houses on the same night. Return the maximum total amount you can collect.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.