#C4993. Binary Tree Depth and Leaf Count

    ID: 48592 Type: Default 1000ms 256MiB

Binary Tree Depth and Leaf Count

Binary Tree Depth and Leaf Count

In this problem, you are required to implement a binary search tree with two main functionalities:

  • Maximum Depth Calculation: Compute the depth of the tree, where the depth (or height) is defined recursively as $$depth(node)=\begin{cases}0 & \text{if } node \text{ is null}\\1+\max(depth(node.left),\,depth(node.right)) & \text{otherwise}.\end{cases}$$
  • Leaf Count: Count the number of leaf nodes in the tree (i.e., nodes with no children).

You will receive a sequence of integers to insert into the tree in the given order. After building the tree, output its maximum depth and the number of leaf nodes.

inputFormat

The input is read from standard input (stdin) and is formatted as follows:

  1. The first line contains a single integer n which represents the number of nodes to be inserted into the tree.
  2. If n > 0, the second line contains n space-separated integers, representing the values to be inserted into the binary tree in the given order. If n is zero, no further input is provided.

outputFormat

The output should be written to standard output (stdout) and must consist of two lines:

  1. The first line should contain the maximum depth (height) of the binary tree.
  2. The second line should contain the number of leaf nodes in the binary tree.
## sample
0
0

0

</p>