In this HackerRank XML2 - Find the Maximum Depth 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.

HackerRank XML2 - Find the Maximum Depth in python problem solution

HackerRank XML2 - Find the Maximum Depth in python problem solution

import xml.etree.ElementTree as etree

def find_depth(x, depth, l):
	for child in etree.ElementTree(x).getroot():
		if child != None:
			l.append(depth)
			find_depth(child, depth + 1, l)

	return l

num = input()
xml = ''
for i in range(num):
	xml += raw_input()
if num > 2:
	depth = 1
	l = []
	found = find_depth( etree.fromstring(xml), depth, l )
	print max(found)
else:
	print 0