Problem Name: Python - XML2 - Find the Maximum Depth

Problem Link:  

In this HackerRank Functions in PYTHON problem solution,

You are given a valid XML document, and you have to print the maximum level of nesting in it. Take the depth of the root as 0.

Input Format

The first line contains N. the number of lines in the XML document.
The next N lines follow containing the XML document.

Output Format


Output a single line, the integer value of the maximum level of nesting in the XML document.


Sample Input


<feed xml:lang='en'>
    <subtitle lang='en'>Programming challenges</subtitle>
    <link rel='alternate' type='text/html' href=''/>


Sample Output





Here, the root is a feed tag, which has depth of 0.

The tags title, subtitle, link and updated all have a depth of 1.

Thus, the maximum depth is 1.



Code Examples

#1 Code Example with Python Programming

Code - Python Programming

def depth(elem, level):
    global maxdepth
    maxdepth = max(maxdepth, level + 1)
    for child in elem:
        depth(child, level + 1)
Copy The Code & Try With Live Editor


[Solved] Validating UID in PYTHON solution in Hackerrank
[Solved] Standardize Mobile Number Using Decorators in PYTHON solution in Hackerrank