Width of the trees P52155


Statement
 

pdf   zip

thehtml

Write a program that reads the shape of various binary trees, and prints the width of each one. We define the width of a tree as the maximal number of nodes that has at any of its levels (or zero, if the tree is empty).

Input

Input consists of the description of various trees as it is explained at the exercise , with an exception: All the values are 0, because the content of the nodes here is not important.

Output

Your program must print the width of each given tree.

Public test cases
  • Input

    10
    0 0 0 -1 0 -1 -1 0 -1 -1 0
    0 -1 -1 0 0 -1 0 -1 -1 -1
    
    3
    0 0 0 -1 -1 -1 -1
    

    Output

    4
    1
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++