|| C++ Solution 💻|| Easy 😊 || Explained🤔 || 100% Faster 🚀 || O(N)🔥||
LeetCode Problem - Maximum Level Sum of a Binary TreeIntuitionTo find the level with the maximum sum in a binary tree, we can traverse the tree level by level w
# LeetCode Problem - Maximum Level Sum of a Binary Tree


## Intuition
To find the level with the maximum sum in a binary tree, we can traverse the tree level by level while keeping track of the sum at each level.  

## Approach
- Use a queue to perform a level-order traversal (BFS).  
- At each level, compute the sum of all node values.  
- Keep track of the maximum level sum and update the answer whenever a larger sum is found.  

## Complexity
- **Time complexity:** \(O(N)\), where \(N\) is the number of nodes in the tree, as each node is visited once.  
- **Space complexity:** \(O(W)\), where \(W\) is the maximum width of the tree, due to queue storage.  


# Code
```cpp []
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    int maxLevelSum(TreeNode* root) {
        queue<TreeNode *> q;
        int maxi{INT_MIN}, level{0},ans{0};
        q.push(root);
        while(!q.empty()){
            int size = q.size();
            int lsum{0};
            while(size){
                TreeNode * node = q.front();
                q.pop();
                lsum+=node->val;
                size--;
                if(node->left!= nullptr)
                    q.push(node->left);
                if(node->right!= nullptr)
                    q.push(node->right);
            }
            level++;
            if(maxi<lsum){  
                maxi = lsum;
                ans = level;
            }
        }
    return ans;
    }
};
```
['C++']