Breadth-first search and LCA
Intuition\n Describe your first thoughts on how to solve this problem. \nLowest Common Ancestor\n\n# Approach\n Describe your approach to solving the problem. \
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nLowest Common Ancestor\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFind out the last level of the tree and store the left and right nodes of that level, then we can simply find the lowest common ancestor of those 2 nodes and return that as the answer.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {\n        if(!root || root == p || root == q)\n            return root;\n        TreeNode* left = lowestCommonAncestor(root->left, p, q);\n        TreeNode* right = lowestCommonAncestor(root->right, p, q);\n        if(!left)\n            return right;\n        if(!right)\n            return left;\n        return root;\n    }\n    TreeNode* subtreeWithAllDeepest(TreeNode* root) {\n        vector<vector<TreeNode*>> vec;\n        queue<TreeNode*> q;\n        q.push(root);\n        while(!q.empty()) {\n            int n = q.size();\n            vector<TreeNode*> temp;\n            while(n--) {\n                TreeNode* node = q.front();\n                q.pop();\n                temp.push_back(node);\n                if(node->left)\n                    q.push(node->left);\n                if(node->right)\n                    q.push(node->right);\n            }\n            vec.push_back(temp);\n        }\n        vector<TreeNode*> lastlvl = vec[vec.size()-1];\n        TreeNode* left = lastlvl[0];\n        TreeNode* right = lastlvl[lastlvl.size()-1];\n        return lowestCommonAncestor(root, left, right);\n    }\n};\n```
['Breadth-First Search', 'C++']