Amazon Interview Question

Algorithms on tree