Intuitive 🔥 and simple approach in JS || B86.34% in runtime
Intuition\nSimple Level-order-traversal / BFS for getting the sum of the node values in each level and that\'s it, your question get solved.\n\n# Approach\n1. D
# Intuition\nSimple Level-order-traversal / BFS for getting the sum of the node values in each level and that\'s it, your question get solved.\n\n# Approach\n1. Do level-order-traversal / BFS and get the sum of node values for each level\n2. Store the maxSum and compare in each stage, if it\'s greater then the old maxSum then update the maxSum and store the level.\n\n> ## IF YOU FIND IT HELPFUL, PLEASE GIVE IT A `UPVOTE \u2B06`\n\n# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(w)$$ max-width of the tree\n\n![statistics.PNG](https://assets.leetcode.com/users/images/dc880b78-de8a-4d4d-96e5-00b5ab8aa2fb_1686815621.8353844.png)\n\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n *     this.val = (val===undefined ? 0 : val)\n *     this.left = (left===undefined ? null : left)\n *     this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar maxLevelSum = function (root) {\n    let ans = 1;\n    if (!root) return ans;\n\n    let qu = [root];\n    let maxSum = root.val;\n    let height = 1;\n    while (qu.length) {\n        const n = qu.length;\n        let sum = 0;\n        for (let i = 0; i < n; i++) {\n            const node = qu.shift();\n            sum += node.val;\n            if (node.left) qu.push(node.left);\n            if (node.right) qu.push(node.right);\n        }\n        if(sum > maxSum){\n            maxSum = sum;\n            ans = height;\n        }\n\n        height++;\n    }\n    return ans;\n};\n```
['JavaScript']