CT023

Lowest Sum Grove Level

MediumAcceptance: 0.0%

A grove in Codetikki is a binary tree where each node carries a value. The shamans want to find which level of the grove has the smallest total sum. Given a binary tree, return the level (0-indexed) that has the minimum sum. If multiple levels tie, return the smallest level. Input: tree in level-order with "null" for absent nodes. Output: the level number with minimum sum.

Example 1:

Input: 1 2 3 4 5 null 6
Output: 0

Example 2:

Input: 5 2 8 1 3 6 9
Output: 2

Constraints:

1 <= number of nodes <= 10^4 -10^4 <= node value <= 10^4

Tags:

trees bfs queue
Loading...
Test Cases:No test cases
No test cases available.