Simple recursive Java Solution 
\n\tpublic int depth(TreeNode root){\n\t\tif(root == null ) return 0;\n\t\treturn Math.max(depth(root.left),depth(root.right))+1;\n\t}\n\tpublic TreeNode subtre
```\n\tpublic int depth(TreeNode root){\n\t\tif(root == null ) return 0;\n\t\treturn Math.max(depth(root.left),depth(root.right))+1;\n\t}\n\tpublic TreeNode subtreeWithAllDeepest(TreeNode root) {\n\t\t\tif( root == null ) return null;\n\t\t\tint left =  depth(root.left);\n\t\t\tint right = depth(root.right);\n\t\t\tif( left  == right ) return root;\n\t\t\tif( left > right ) return subtreeWithAllDeepest(root.left);\n\t\t\treturn subtreeWithAllDeepest(root.right);\n\t}\n```\n\t\t\n\nThe time complexity of above code is O(N^2) since a binary tree can degenerate to a linked list, the worst complexity to calculate depth is O(N) and so the overall time complexity is O(N^2). Here is the memoized version:\n\nTime complexity: O(N)\n\n ```\n public int depth(TreeNode root,HashMap<TreeNode,Integer> map){\n         if(root == null ) return 0;\n         if( map.containsKey(root) ) return map.get(root); \n         int max = Math.max(depth(root.left,map),depth(root.right,map))+1;\n         map.put(root,max);   \n         return max;\n    }\n    public TreeNode dfs(TreeNode root, HashMap<TreeNode,Integer> map){\n        int left =  depth(root.left,map);\n        int right = depth(root.right,map);\n        if( left  == right ) return root;\n        if( left > right ) return dfs(root.left,map);\n        return dfs(root.right,map);\n    }\n    public TreeNode subtreeWithAllDeepest(TreeNode root) {\n        if( root == null ) return null;\n        HashMap<TreeNode,Integer> map = new HashMap<>();\n        depth(root,map);\n        return dfs(root,map);\n    }\n```\n\t\t
[]