Given parent array representation of the tree, find the height of the tree. In this parent array representation, a node would be constructed with values taken from indices of this array. For element parent[i], a node would be constructed with value 'i'. And parent node for this constructed node with value 'i' would be node with value parent[i]. If parent[i] is -1, then we make the node with value 'i' as the root of the tree. For example, for the parent array {3, 5, 0, -1, 5, 3, 0}:

parent[0] = parent[5] = 3, therefore node with value 3 would be parent node for nodes with values 0 and 5.

parent[1] = parent[4] = 5, therefore node with value 5 would be parent node for nodes with values 1 and 4.

parent[2] = parent[6] = 0 implies that node with value 0 would be parant node for nodes with values 2 and 6.

parent[3] = -1 therefore, node 3 would be the root node for this tree.

The complete constructed tree for parent array {3, 5, 0, -1, 5, 3, 0} would look like following:

And output of the program should be the height of this tree that is 3.

For parent array {-1, 0, 1, 5, 1, 0}, constructed binary tree would be :

And output of the program should be the height of this tree that is 3.