Amazon Interview Question

Coding question of tree and graph