Implement merging of two key-value trees by summing values along matching key paths.
Unlock detailed company stats for this questionUpgrade
Each node has a key and a value that is the sum of itself and its children. It is not a binary tree. When merging, absent branches are created and values of existing branches are summed. Keys are unique among the children of a single parent. Only nodes with the same key path from the root merge, so an M under C does not merge with an M under W. Child nodes may be stored in any order. Example: source ROOT:22 (W:2, K:16, C:4) merged into target ROOT:20 (W:5, K:2, R:13) gives ROOT:42 with W:7, K:18, C:4, R:13. Implement TreeNode and MergeTwoTrees::merge(source, target).
Community answers
No answers contributed by the community yet.
Related courses

Course

Course
Course
