JavaScript | Height of Binary Tree

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)


Calculate the height of binary tree


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

Follow me for more coding interview.

This problem is very popular in the coding interviews.

Keep learning, keep growing!

Don’t forget to follow me for more such articles, and subscribe to our newsletter.

Let’s connect on LinkedIn!. Please read more for more data structure javascript question.