The weight increases from the leaf to the root.
However, the following situation is not clearly defined. I will illustrate it using a tree structure.
a / \ b c \ d
What is the weight of a? Is it 2 to 3?
What I found more surprising is that
b, which is a leaf, has weight 2. Even though we're told that "the leaf level integers have weight 1".
In my opinion from what the question says, the depth of a is 2 for left child and 3 for right child.
This question can easily mislead readers. This is not how we generally define the "depth" of a node in the tree. If I remember correctly, "Depth" means the length from root to a node and "height" means the length from the node to its deepest child.
Apparently, in this question, neither of them is our case. I think the question should emphasize their special definition "depth", to avoid misunderstand.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.