HackerRank XML2 Find the Maximum Depth solution in Python YASH PAL, 31 July 202417 January 2026 HackerRank XML2 Find the Maximum Depth solution in Python – In this XML2 find the maximum depth problem, 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 solution in Python 2.# Enter your code here. Read input from STDIN. Print output to STDOUT def depth(tree): dp = 0 if tree is not None: for i in tree: dp = max(dp, depth(i) + 1) return dp n = int(raw_input()) xml = "" for i in range(n): xml += raw_input() import xml.etree.ElementTree as etree tree = etree.fromstring(xml) print depth(tree)XML2 Find the Maximum Depth solution in Python 3.global maxdepth maxdepth = -1 def depth(elem, level): global maxdepth if (level == maxdepth): maxdepth += 1 for child in elem: depth(child, level + 1)Problem solution in pypy programming.maxdepth = 0 def depth(elem, level): global maxdepth if (level == maxdepth): maxdepth += 1 for child in elem: depth(child, level + 1) Problem solution in pypy3 programming.maxdepth = 0 def depth(elem, level): global maxdepth for child in elem: depth(child, level+1) maxdepth = max(maxdepth, level+2) coding problems solutions Hackerrank Problems Solutions Python Solutions HackerRankPython