Paytm interview question

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