Create an array to store depth of all nodes / and initialize depth of every node as 0 ( an invalid value ) . Depth of root is 1
var depth = Array ( n ) . fill ( 0 ) ; for ( i = 0 ; i < n ; i ++ ) { depth [ i ] = 0 ; }