BFS solution
\n\nclass Solution:\n    def subtreeWithAllDeepest(self, root):\n        if not root: return\n        parent = {} # child: its parent\n        queue = set([root
```\n\nclass Solution:\n    def subtreeWithAllDeepest(self, root):\n        if not root: return\n        parent = {} # child: its parent\n        queue = set([root])\n        while queue:\n            new_queue = set()\n            for n in queue:\n                if n.left:\n                    new_queue.add(n.left)\n                    parent[n.left] = n\n                if n.right:\n                    new_queue.add(n.right)\n                    parent[n.right] = n\n            if not new_queue:\n                break\n            else:\n                queue = new_queue\n        # queue == all the deepest nodes\n        # find its closest shared parent\n        while queue:\n            if len(queue) == 1:\n                return queue.pop()\n            new_queue = set()\n            for n in queue:\n                new_queue.add(parent[n])\n            queue = new_queue\n```
[]