Practice Cousins in Binary Tree II
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Cousins in Binary Tree II
Problem Statement
Given the root of a binary tree, replace the value of each node in the tree with the sum of all its cousins' values. Two nodes of a binary tree are cousins if they have the same depth with different parents. Return the root of the modified tree. Note that the depth of a node is the number of edges in the path from the root node to it.
Source: Cousins in Binary Tree II on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
root = [5,4,9,1,10,null,7]
[0,0,0,7,7,null,11]
# Example 2
root = [3,1,2]
[0,0,0]
Constraints
Related LeetCode Problems
Practice more problems similar to Cousins in Binary Tree II.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.