Back to problems

Copy Neighbor Sums Between Binary Trees

Algorithm · Snowflake · Medium

(This task is a variant of the standard "merge two binary trees" problem. If you have not solved that base problem yet, it may help to start there.) You are given trees, a list of binary trees. For any node, its neighbor sum is the node's own value plus the values of its left and right children, treating a missing child as 0. Now process every tree in trees except the final one, moving left to right, and apply its neighbor-sum contributions to that final tree: If a source…

Checking your access…