Question DSA-TREE-0044
MediumWhat is the output of this code?
class N:
def __init__(self, v, l=None, r=None):
self.v, self.l, self.r = v, l, r
best = 0
def depth(n):
global best
if not n:
return 0
a, b = depth(n.l), depth(n.r)
best = max(best, a + b)
return 1 + max(a, b)
t = N(1, N(2, N(4), N(5, N(6))), N(3))
depth(t)
print(best)
- A.
3
- B.
5
- C.
6
- D.
4
Sign up free to see the answer and a step-by-step explanation.