FOR DFS FANS ONLY!!!!! {Easy to Understand and Specially designed for beginners}
Yeah I know that IT can be solved usinf bfs but as this is for dfs fans , So I just came up with\nDFS Solution + Power OF STL in c++\n\nLet\'s Have a Look On CO
Yeah I know that IT can be solved usinf bfs but as this is for dfs fans , So I just came up with\nDFS Solution + Power OF STL in c++\n\nLet\'s Have a Look On CODE\n\nBEST OF LUCK!!!!!!\n\n\n```\nvoid preorder(TreeNode* root, map<int,int>&mp, int level)\n{\n    if(root==NULL) return;\n    level++;\n    if(mp.count(level)==0)// first time\n    mp[level]=root->val;\n    else    \n    mp[level]+=root->val;\n    \n    preorder(root->left,mp,level);\n    preorder(root->right,mp,level);\n}\n\n\nclass Solution {\npublic:\n   int maxLevelSum(TreeNode* root) {\n        if(root==NULL) return 0;\n        map<int,int>mp; // the key store the level and the value stores the sum at\n                            // that level\n       int level=0; \n       preorder(root,mp,level);\n       \n       int ans;\n       int maxa=INT_MIN;\n       for(auto x: mp)\n       {\n           if(x.second>maxa)\n           {\n               maxa=x.second;\n               ans=x.first;\n           }\n       }\n       \n       return ans;\n      \n    }\n};\n```
[]