← Questions

Merge two config trees with per-node merge rules

0
GoogleCodingLast asked Oct 2026

Two configuration files have been parsed from YAML into trees of dicts, lists and plain values: a base and an overlay. Merge the overlay into the base.

Each node can carry its own merge rule, given as a table from a dotted node path to a rule name. Rules include: merge two dicts key by key (recursing into shared keys), take the overlay's node, keep the base's node, concatenate two lists, and merge two lists of dicts by matching a key field. A node with no rule merges dicts and otherwise takes the overlay.

There are many rules in the real exercise, so design the walk so that adding a rule doesn't touch it. Cover keys present on one side only, list order, and a dict meeting a list.

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