Problem 5
Config Merge with Deletions
MEDIUMBUILD
Hash Map+2
Hash MapRecursionImplementation
Implement merge_configs(base, override) that deep-merges two Python dicts and returns a new dict. Keys present in only one dict are kept as-is. If both values are dicts, merge recursively. Otherwise the override value wins, except if the override value is None, the key is removed from the result. Lists are never merged; the override list replaces the base list. Do not mutate base or override.
Examples
Example 1
Input
base = {"a": 1, "b": {"x": 1, "y": 2}}
override = {"b": {"y": 99, "z": 3}}Output
{"a": 1, "b": {"x": 1, "y": 99, "z": 3}}Example 2
Input
base = {"a": 1, "b": {"x": 1}, "c": 3}
override = {"b": None, "c": {"k": 1}}Output
{"a": 1, "c": {"k": 1}}Note
None deletes the key; a non-dict override replaces the base dict.
Constraints
- Values may be dicts, lists, strings, numbers, booleans, or None
- Nesting depth is at most 20
Follow-up
How would you detect and reject cyclic references in input objects?
Hints
Console output will appear here...