#K13001. Teardrop Forest Height

    ID: 23815 Type: Default 1000ms 256MiB

Teardrop Forest Height

Teardrop Forest Height

You are given one or more binary trees represented in level-order. In the level-order array, a value of -1 represents a null node. Your task is to compute the height of each binary tree.

The height of a binary tree is defined as follows. For an empty tree, \(height = 0\). Otherwise, \(height = 1 + \max(\text{height of left subtree},\, \text{height of right subtree})\).

You need to process multiple test cases.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains an integer T representing the number of test cases.
  • For each test case:
    • The first line contains an integer N which is the number of nodes in the level-order traversal.
    • If N is not zero, the next line contains N space-separated integers representing the level-order traversal of the tree. A value of -1 indicates a null node. If N equals 0, it means the tree is empty.

outputFormat

For each test case, output the height of the corresponding binary tree on a separate line to standard output (stdout).

## sample
2
9
1 2 3 -1 -1 4 5 -1 -1 -1 -1 6 7
7
1 2 3 -1 4 -1 5
4

3

</p>