Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on.
Return the smallest level X such that the sum of all the values of nodes at level X is maximal.
Example 1:
Input: root = [1,7,0,7,-8,null,null]
Output: 2
Explanation: 
Level 1 sum = 1.
Level 2 sum = 7 + 0 = 7.
Level 3 sum = 7 + -8 = -1.
So we return the level with the maximum sum which is level 2.
Example 2:
Input: root = [989,null,10250,98693,-89388,null,null,null,-32127]
Output: 2
Constraints:
The number of nodes in the tree is in the range [1, 104].
-105 <= Node.val <= 105

class Solution:
    def maxLevelSum(self, root: TreeNode) -> int:
        
        vals={}
        current=[root]
        vals[1]=root.val
        max1=0
        level=0
        cl=1
        
        while len(current):
            nodes=current
            children=[]
            sum1=0
            for node in nodes:
                
                if node.left:
                    children.append(node.left)
                    sum1+=node.left.val
                if node.right:
                    children.append(node.right)
                    sum1+=node.right.val
            
            vals[cl+1]=sum1
            if sum1>=max1:
                level=cl+1
                max1=sum1
            
            if len(children)>0:
                current=children
                cl+=1
            
            else:
                break
        
        
            
        return level


class Solution:
    def maxLevelSum(self, root: TreeNode) -> int:
        
        vals={}
        current=[root]
        vals[1]=root.val
        max1=0
        level=0
        cl=1
        
        while len(current):
            nodes=current
            children=[]
            sum1=0
            for node in nodes:
                
                if node.left:
                    children.append(node.left)
                    sum1+=node.left.val
                if node.right:
                    children.append(node.right)
                    sum1+=node.right.val
            
            vals[cl+1]=sum1
            if sum1>=max1:
                level=cl+1
                max1=sum1
            
            if len(children)>0:
                current=children
                cl+=1
            
            else:
                break
        
        
            
        return level
