Simple java by just using two global variables 0ms runtime
Using a global variable to store max height at each instance and the result root at that instance.\nTraversing the left subtree first and then the right subtree
Using a global variable to store max height at each instance and the result root at that instance.\nTraversing the left subtree first and then the right subtree and calculating the height of left and right subtree and if they are equal to maximum height till that moment then then the current node becomes the smallest subtree with the deepest nodes so store it in variable res and repeat this for all the nodes.\n\n```\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode() {}\n *     TreeNode(int val) { this.val = val; }\n *     TreeNode(int val, TreeNode left, TreeNode right) {\n *         this.val = val;\n *         this.left = left;\n *         this.right = right;\n *     }\n * }\n */\nclass Solution {\n    int maxHeight;\n    TreeNode res;\n    public TreeNode subtreeWithAllDeepest(TreeNode root) {\n        res = root;\n        traverse(root, 0);\n        return res;\n    }\n    int traverse(TreeNode root, int height){\n        if(root == null){\n            if(height > maxHeight) maxHeight = height;\n            return height;\n        }\n        int left = traverse(root.left, height+1);\n        int right = traverse(root.right, height+1);\n        if(left == maxHeight && right == maxHeight){\n            res = root;\n        }\n        return Math.max(left, right);\n    }\n}\n\n```
['Recursion', 'Java']