Easy to understand ✅|| O(n) explained sol.❗ || A/Hints 📝|| BFS approach || Level order traversal
\n# Approach\nA/Hints, we are using level order Traversal and using map to take record of maximum sum of each level(BFS) along with its level count.\nThen trave
\n# Approach\nA/Hints, we are using level order Traversal and using map to take record of maximum sum of each level(BFS) along with its level count.\nThen traverse through map and return the level having maximum sum.\n\n# Complexity\n- Time complexity:\nO(N) where N is the number of nodes in the binary tree.\n\n- Space complexity:\nO(N) where N is the number of nodes in the binary tree.\n\n# Code\n```\n\nclass Solution {\npublic:\n    int maxLevelSum(TreeNode* root) {\n        \n        map<int,int> m; //Declare map.\n        if(!root) return 0;\n\n        queue<TreeNode*> q; // Declare queue.\n        q.push(root);\n\n        int lvl = 1; // Initialize level count by 1.\n        // Run loop until the queue is empty.\n        while(!q.empty()) {\n\n            int sum = 0; //Initialize sum by 0 for each loop.\n            int n = q.size();\n\n            for(int i=0; i<n; i++) {\n\n                TreeNode* temp = q.front();\n                q.pop();\n                sum += temp->val; // Add the node -> val in sum.\n                if(temp -> left!=NULL) q.push(temp->left); \n                if(temp -> right!=NULL) q.push(temp->right);\n\n            }\n            // Insert the sum of each level into the map m as an key if it is not present already and level will be it\'s value.\n            if(m.find(sum) == m.end()) {\n                m[sum] = lvl;\n            }\n\n            lvl++;\n        }\n\n        int max_sum = INT_MIN;\n        int ans = 0;\n        // Traverse through map and return the level having maximum sum.\n        for(auto it: m) {\n            if(max_sum < it.first) {\n                max_sum = it.first;\n                ans = it.second; \n            }\n        }\n\n        return ans;\n    }\n};\n```
['Breadth-First Search', 'Queue', 'Ordered Map', 'C++']