✅BFS🔥 | QUEUE🔥 | TYPESCRIPT🔥 | 94%🔥!!!✅
\n\n# Approach\n Describe your approach to solving the problem. \nIn this solution we have:\n    -Time complexity O(n) where n is count of all nodes\n    -Space
![image.png](https://assets.leetcode.com/users/images/24f0c96b-c837-43a9-a76e-77c470c59875_1698504331.5287795.png)\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nIn this solution we have:\n    -Time complexity O(n) where n is count of all nodes\n    -Space complexity O(w) where w is count of all nodes in one level(width of level)\n    The main point of this approach that we moving down our tree and for each level count sum of nodes value. Also we use dynamic queue for changing level. It mean that next level appears when we finished iteration for every nodes of current level and after that we change the level and check sum of our level, if it more than our current max sum, we change max to current sum  \n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(w)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nfunction maxLevelSum(root: TreeNode | null): number {\n    let max = -Infinity;\n    let maxLevel = 0;\n    let level = 0;\n    let queue = [root];\n\n    while(queue.length) {\n        let sum = 0;\n        const tmp = [];\n        for(let i = 0; i < queue.length; i++) {\n            const node = queue[i];\n            if (node.left) tmp.push(node.left);\n            if (node.right) tmp.push(node.right);\n            sum += node.val;\n        }\n        queue = tmp;\n        level++\n        if (sum > max) {\n            max = sum;\n            maxLevel = level;\n        }\n    }\n\n    return maxLevel;\n};\n```
['Breadth-First Search', 'Queue', 'TypeScript']