Amazon interview question

1. Leetcod question using tree structure.