C++ || Easy To Understand || BFS
Intuition\nAs it is mentioned clearly in question that we want the minimal value of level which have maximum sum therefore we will do LEVEL ORDER TRAVERSAL.\n D
# Intuition\nAs it is mentioned clearly in question that we want the minimal value of level which have maximum sum therefore we will do **LEVEL ORDER TRAVERSAL**.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nWe will traverse tree in level order fashion and at every level we will calculate the sum of all values of nodes at that level and if the sum at that level is greater than the max sum, we will update our max sum. As here we are doing ```if(curr_sum > max_sum)``` the minimal level part mentioned in question will also be taken care by this condition.\nFor level order traversal we use queue data structure.\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) (Approx)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n**PLEASE UPVOTE IF YOU LIKE MY SOLUTION**\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        int curr_level = 1;\n        int ans_level = 1;\n        queue<TreeNode*> q;\n        q.push(root);\n        int max_sum = root->val;\n\n        while(q.empty()==0){\n            int curr_sum = 0;\n            int n = q.size();\n            for(int i = 0;i<n;i++){\n                 auto curr = q.front();\n                 q.pop();\n                 if(curr->left != NULL){\n                     q.push(curr->left);\n                 }\n                 if(curr->right !=NULL){\n                     q.push(curr->right);\n                 }\n                 curr_sum+=curr->val;\n            }\n            if(curr_sum>max_sum){\n                max_sum = curr_sum;\n                ans_level = curr_level;\n            }\n            curr_level += 1;\n        }\n        return ans_level;\n    }\n};\n```
['Tree', 'Breadth-First Search', 'Queue', 'Binary Tree', 'C++']