A binary tree’s maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

Time Complexity: O(N)

Approach,

Calculate the height of binary tree

Implementation,

var maxDepth = function(root) {
if (root === null) return 0
return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1
};

Follow me for more…

--

--

iAmSonika | www.startlearncoding.com

iAmSonika | www.startlearncoding.com

Working in Walmart as UI Developer | Mentor | React | JavaScript | HTML | CSS