Amazon Interview Question

Leetcode style question, similar to least common ancestor