Beats 89% solutions, Java
\n\n# Approach\n \nThis is a simple level order traversal. We keep adding the sum of nodes in each level and compare it with the maximum sum of the previous lev
\n\n# Approach\n \nThis is a simple level order traversal. We keep adding the sum of nodes in each level and compare it with the maximum sum of the previous level. \n\nBut we don\'t need to return the maximum sum here. Instead we need to return the level of the maximum sum. For that case, we keep a counter to increase the level and as soon as the maximum sum in any level is found, we store that particular level in another variable.\n\n\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode() {}\n *     TreeNode(int val) { this.val = val; }\n *     TreeNode(int val, TreeNode left, TreeNode right) {\n *         this.val = val;\n *         this.left = left;\n *         this.right = right;\n *     }\n * }\n */\nclass Solution {\n    public int maxLevelSum(TreeNode root) {\n\n        Queue<TreeNode> q = new LinkedList<>();\n\n       int level =0;\n       int minlevel=0;\n       int max = Integer.MIN_VALUE;\n\n        if(root==null)\n        return 0;\n\n        q.add(root);\n\n        while(!q.isEmpty())\n        {\n            int size=q.size();\n            level++;\n            \n            int sum=0;\n\n            for(int i=0;i<size;i++)\n            {\n            TreeNode node = q.remove();\n\n            sum +=node.val;\n\n            if(node.left!=null)\n            q.add(node.left);\n\n            if(node.right!=null)\n            q.add(node.right);\n            }\n            if(sum>max)\n            {\n                max = sum;\n                minlevel = level;\n            }\n        }\n        return minlevel;\n    }\n}\n```
['Tree', 'Breadth-First Search', 'Binary Tree', 'Java']