World's most easy Solution You Will Ever Find.. Beats 100%..
IntuitionWe want to find the Lowest Common Ancestor (LCA) of the deepest leaf nodes in a binary tree.First, we find the maximum depth of the tree (i.e., the dee
# Intuition
We want to find the Lowest Common Ancestor (LCA) of the deepest leaf nodes in a binary tree.

First, we find the maximum depth of the tree (i.e., the deepest level).

Then, we do a DFS traversal, and at each node:

If both left and right children contain deepest leaves, then this node is the LCA.

If only one side has deepest leaves, we return that side up the recursion.

The moment both sides return non-null, that node becomes the LCA.

# Approach
Find the maximum depth using a simple recursive function maxDepth.

Do a second DFS (dfs function):

Track the current depth (len).

When you reach depth == maxDepth - 1, return the node (it's one level before deepest).

For each node, recursively check left and right children.

If both return non-null, current node is the LCA of deepest leaves.

# Complexity
- Time complexity:
O(n)

- Space complexity:
O(h)

# Code
```cpp []
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    TreeNode* subtreeWithAllDeepest(TreeNode* root) 
    {
        int maxD = maxDepth(root);
        return dfs(root,maxD,0);
    }
    TreeNode* dfs(TreeNode* root,int maxD,int len)
    {
        if(root == NULL) return NULL;
        if(maxD-1 == len) return root;

        TreeNode* left = dfs(root->left,maxD,len+1);
        TreeNode* right = dfs(root->right,maxD,len+1);

        if(left && right) return root;
        return left?left:right;
    }
    int maxDepth(TreeNode* root)
    {
        if(root == NULL) return 0;
        return 1 + max(maxDepth(root->left),maxDepth(root->right));
    }
};
```
['C++']