# Binary Tree Max Depth

**Given the root node of a binary tree, write a function findMaxDepth that returns an integer corresponding to the maximum depth.**

The maximum depth is going to be the node with the level furthest from the root. The root node is a 0 depth, and an empty input would be considered -1.

```
9 // root = level 0
/ \
5 22 // level 1
/ \ \
1 7 30 // level 2
/
25 // level 3
findMaxDepth(root); // returns 3
```

The tree nodes will use the following implementation:

```
class BinaryNode {
constructor(data) {
this.data = data;
this.left = null;
this.right = null;
}
}
```

## Breakdown

Table of Contents

### Validate My Answer

This can be solved iteratively or recursively using either DFS or BFS. Follow whichever path you feel most comfortable with, but remember to mention that a recursive solution could cause a stack overflow.

All you need to track is the max depth at any point. If the current max you've found is larger than the depth of the current level, then we know to ignore this depth and continue looking. If the current depth is larger than the max we found, we store this as the new max depth.

This can be done in

*O(n)*time and space.

Table of Contents

Test Results

Run your code and see results here...

### Binary Tree Max Depth

**Given the root node of a binary tree, write a function findMaxDepth that returns an integer corresponding to the maximum depth.**

The maximum depth is going to be the node with the level furthest from the root. The root node is a 0 depth, and an empty input would be considered -1.

```
9 // root = level 0
/ \
5 22 // level 1
/ \ \
1 7 30 // level 2
/
25 // level 3
findMaxDepth(root); // returns 3
```

The tree nodes will use the following implementation:

```
class BinaryNode {
constructor(data) {
this.data = data;
this.left = null;
this.right = null;
}
}
```