Amazon Interview Question

Not too difficult. Some tree and array problems.