O(N) || BFS Approach || C++ || Very Easy to Understand
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nThe time complexity of the given code is O(N), where N is the number of nodes in the binary tree.\n\nIn the code, a level-order traversal is performed using a queue. In the worst case scenario, all nodes of the binary tree will be visited once, so the time complexity is proportional to the number of nodes in the tree.\n\nThe while loop iterates until the queue becomes empty, and in each iteration, the code processes each node once. The number of iterations depends on the number of nodes in the tree, which is N.\n\nTherefore, the time complexity of the code is O(N).\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int maxLevelSum(TreeNode* root) {\n\n          int ans = -1;\n          int lvl = 0;\n          int maxSum = INT_MIN;\n          queue<TreeNode*> q;\n\n          q.push(root);\n\n          while(!q.empty()){\n              \n              lvl++;\n              int size = q.size();\n              int temp = 0;\n              for(int i=0;i<size;i++){\n              TreeNode* node = q.front();\n              q.pop();\n               \n                temp += node->val;\n                \n                if(node->left)\n                 q.push(node->left);\n\n                if(node->right)\n                 q.push(node->right); \n\n              }\n\n              if(temp > maxSum){\n                  ans = lvl;\n                  maxSum = temp;\n              }\n          }\n        \n        return ans;\n    }\n};\n```
['Breadth-First Search', 'Binary Tree', 'C++']