Compute tree diameter | Amazon Interview Question