C++ | Using Level Order | O(N) Solution
Approach : Just do Level Order  \n Describe your approach to solving the problem. \n\n# Complexity\n- Time complexity: O(N)\n Add your time complexity here, e.g
# Approach : Just do Level Order  \n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N)  \n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int maxLevelSum(TreeNode* root) {\n        if(root==nullptr)return 0;  //Base case\n        queue<TreeNode*>q;\n        q.push(root);\n        int level=1,anslevel=1,mini = INT_MIN;\n\n        while(!q.empty()){\n            int size = q.size(),sum=0;\n            for(int i=0;i<size;i++){\n                TreeNode*temp = q.front();\n                sum+=temp->val;\n                q.pop();\n                if(temp->left)q.push(temp->left);\n                if(temp->right)q.push(temp->right);\n            }\n            if(sum>mini){\n                mini = sum;\n                anslevel = level;\n            }    \n            level++;\n        }\n        return anslevel;\n    }\n};\n```
['C++']