Problem 40 of 75

Maximum Level Sum of a Binary Tree

MediumNot solved yetInterview me on this
Before you code · which pattern fits?

The problem

Given the root of a binary tree with levels numbered from 1, return the smallest level x such that the sum of all node values at level x is maximal.

[1,7,0,7,-8,null,null] → 2

Your solution runs against 2 unit tests, including edge and large-value cases.

Loading...

Test console · 2 unit tests

Submit your code to run it against all 2 unit tests. Results appear here.

JavaScript, TypeScript & Python run sandboxed in your browser; other languages run on the execution server. Your code is saved locally as you type.

Hint

Reference solution

Video explanation

Maximum Level Sum of a Binary Tree, explainedcodestorywithMIK