You are given two N-ary trees A and B. Each node has:
key
(string): unique among siblings (i.e., within a node’s children list, no two children share the same key)
value
(any scalar, e.g., string/int)
children
(list of nodes)
You must produce a merged tree M = merge(A, B) using these rules:
key)
:
key
stays the same.
value
is
taken from tree B
(i.e.,
B
overwrites
A
).
children
are formed by merging children lists by key, recursively.
Assume the two input roots have the same key.
Implement a function to merge the two trees and return the merged root.
2 * 10^5