LCA of multiple nodes
The solution is very straight forward. like of problem we solved before LCA of two nodes in a binary tree.Now instead of two nodes we have multiple nodes.\n\ncl
The solution is very straight forward. like of problem we solved before LCA of two nodes in a binary tree.Now instead of two nodes we have multiple nodes.\n```\nclass Solution {\n    public TreeNode subtreeWithAllDeepest(TreeNode root) {\n        Set<TreeNode> deepestNodes = getDeepestNodes(root);\n        return helper(root, deepestNodes);\n    }\n    \n    private TreeNode helper(TreeNode root, Set<TreeNode> deepestNodes){\n        if(root == null) return null;\n        if(deepestNodes.contains(root)) return root;\n        TreeNode left = helper(root.left, deepestNodes);\n        TreeNode right = helper(root.right, deepestNodes);\n        if(left == null){\n            return right;\n        }\n        if(right == null){\n            return left;\n        }\n        return root;\n    }\n    \n    private Set<TreeNode> getDeepestNodes(TreeNode root){\n        Queue<TreeNode> queue = new LinkedList<>();\n        queue.offer(root);\n        Set<TreeNode> set = new HashSet<>();\n        while(!queue.isEmpty()){\n            int size = queue.size();\n            set = new HashSet<>();\n            for(int i = 0; i < size; i++){\n                TreeNode poped = queue.poll();\n                set.add(poped);\n                if(poped.left != null){\n                    queue.offer(poped.left);\n                }\n                if(poped.right != null){\n                    queue.offer(poped.right);\n                }\n            }\n           \n        }\n        return set;\n    }\n}\n```
[]