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**,

**Implementation**,

`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**.

Find the maximum triplet sum in the array

**Input** : arr[] = [1, 2, 3, 0, -1, 8, 10]

**Output** : 21

10 + 8 + 3 = 21

we simply run three-loop and one by one add three-element and compare with the previous sum if the sum of three-element is greater than store in the previous sum.

functionmaxTripletSum(arr, n) { // sort the given array arr.sort();

// Add last three element of the given arrayreturnarr[n - 1] + arr[n - 2] + arr[n - 3];}// input let arr = [ 1, 0, 8, 6, 4, 2 ];let n = arr.length;maxTripletSum(arr, n);// output - 18

Let’s connect on LinkedIn! Please read more for more *data structure javascript question*** **and don’t forget to follow me for more such articles.

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