Simple BFS C++ Solution Beating 100%
Intuition\n Describe your first thoughts on how to solve this problem. \nYou need to traverse the tree level wise, this kind of traversal is done using BFS.\n# 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nYou need to traverse the tree level wise, this kind of traversal is done using BFS.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe just traverse the breadth wise, carrying simultaneous BFS over all elements in the queue. All elements present at the same time in the queue are at the same level, so we sum up the values and compare with the max value seen till now.\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```\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    int maxLevelSum(TreeNode* root) {\n        queue<TreeNode*> q;\n        q.push(root);\n        int ma = 1;\n        int sum = INT_MIN;\n        int level = 1;\n        while(!q.empty()){\n            int size = q.size();\n            int currSum = 0; \n            for(int i=0; i<size; i++){\n                currSum += q.front()->val;\n                if(q.front()->left)q.push(q.front()->left);\n                if(q.front()->right)q.push(q.front()->right);\n                q.pop();\n            }\n            if(currSum > sum){\n                sum = currSum;\n                ma = level;\n            }\n            level++;\n        }\n        return ma;\n    }\n};\n```
['C++']