We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
because they return 1 + max(root.left+root.right) now if root.left or root.right were null then max(blah blah) will return -1 and together they would return 0 as height of that root without left or right subtree..
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tree: Height of a Binary Tree
You are viewing a single comment's thread. Return to all comments →
NO. they haven't mentioned that in the problem. but in editorial they return -1 for root == Null because:
because they return
1 + max(root.left+root.right)
now ifroot.left
orroot.right
were null then max(blah blah) will return-1
and together they would return 0 as height of that root without left or right subtree..