Paytm Interview Question

Traverse a tree and maintain array which contains node’s data and depth for each node.