Java - O(1) space excluding recursion stack - O(N) time
The idea it to propogate a depth val until we reach a null and then return back the maximum depth that was found in the subtree. If both the left and right subt
The idea it to propogate a depth `val` until we reach a `null` and then return back the maximum depth that was found in the subtree. If both the left and right subtree return the same depth, which is also equal to the maximum depth of tree, update the result. \n\n```\nclass Solution {\n\n    int maxDepth = -1; \n    TreeNode[] result = new TreeNode[1]; \n\t\t\n    public TreeNode subtreeWithAllDeepest (TreeNode root) {\n        if(root == null)\n            return root; \n        result[0] = null;  \n        getNode(root , 0); \n        return result[0]; \n    }\n    public int getNode (TreeNode root, int depth){\n        if(root == null)\n            return depth; \n        int l = getNode(root.left, depth+1); \n        int r = getNode(root.right, depth+1); \n\t\t\t\t\n\t\t\t\t// both left and right depth are same and if it is greater than or equal to the maxDepth so far, UPDATE result. \n\t\t\t\t//  `=` in l >= maxDepth, implies that the all the nodes with maximum depth are considered. \n        if(l == r && l >= maxDepth ){\n            maxDepth = l; \n            result[0] = root; \n        }\n\t\t\t\t\n\t\t\t\t// return the maximum depth that was found in this subtree. \n        return Math.max(l,r);\n    }\n}\n```
[]