Video solution | Intuition explained in detail | C++
Video\nHey everyone, i have created a video solution for this problem, I have solved this problem by using maximum depth of binary tree , i have taken advantage
# Video\nHey everyone, i have created a video solution for this problem, I have solved this problem by using **maximum depth of binary tree** , i have taken advantage of background procees of recursion and explained the same in video, how to use recursion to solve this problem, this video is part of my Trees playlist.\nVideo link: https://youtu.be/oqH6mnNxOB4\nPlaylist link: https://www.youtube.com/playlist?list=PLICVjZ3X1Aca0TjUTcsD7mobU001CE7GL\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* res = nullptr;\n    int deepestLevel = 0;\n\n    int dfs(TreeNode* root, int height) {\n        if (!root) return height;\n        int leftHeight = dfs(root->left, height + 1);\n        int rightHeight = dfs(root->right, height + 1);\n        int currLevel= max(leftHeight, rightHeight);\n        if(currLevel>=deepestLevel){\n            deepestLevel=currLevel;\n            if(leftHeight==deepestLevel && rightHeight==deepestLevel){\n                res=root;\n            }\n            \n        }\n        \n        return max(leftHeight, rightHeight);\n    }\n\n    TreeNode* subtreeWithAllDeepest(TreeNode* root) {\n        dfs(root, 0);\n        return res;\n    }\n};\n\n\n```
['C++']