← Questions

Fill a second tree with subtree sums of the first

0
SnowflakeCodingLast asked Sep 2025

You get the roots of two complete binary trees with exactly the same shape. For every node of the second tree, set its value to the sum of the subtree rooted at the matching node of the first tree. Walk both trees together in one post-order pass, and state the time and space it takes.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding