As reported: Amazon SDE-1 university-hire loop (Bangalore, February 2025), round 1 — after a project discussion: Find Median from Data Stream, then Maximum Level Sum of a Binary Tree. No Leadership Principle questions (no time left).
This is LeetCode 1161 — Maximum Level Sum of a Binary Tree.
The root is on level 1, its children on level 2, and so on. Return the smallest level x whose sum of node values is the maximum over all levels.
Example 1
root = [1,7,0,7,-8,null,null]
Output: 2 (level sums: 1, 7, -1)
Example 2
root = [989,null,10250,98693,-89388,null,null,null,-32127]
Output: 2
Constraints: 1 ≤ number of nodes ≤ 10⁴; −10⁵ ≤ Node.val ≤ 10⁵.
Code runner format: LeetCode's test-case format — the tree as a level-order array with null. Implement maxLevelSum(root); the harness prints the level.