Skip to main content
MediumAlgorithms & Data StructuresBuild

Config Merge with Deletions

Implement `merge_config(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...

What you will practice

PythonRecursionData TransformationHash MapImplementation

Requirements

  • Keep the public `merge_config(base, override)` function signature intact.
  • Return a new dict without mutating `base` or `override`.
  • Keep keys that appear in only one input dict.
  • Recursively merge values only when both values are dicts.
  • When values are not both dicts, the override value wins.
  • If an override value is `None`, remove that key from the result.
  • Lists must be replaced by override lists, not merged.

Starter files

main.pyEditable starter

What the judge checks

  • Runs in the python environment with the python-function runner.
  • Uses a 2000ms judge budget.
  • Behavior rules include: No Mutation, Dicts Merge Recursively, Lists Replace Not Merge, None Deletes Key.

Constraints

  • Values may be dicts, lists, strings, numbers, booleans, or None
  • Nesting depth is at most 20

Example behavior

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}}
Input
base = {"a": 1, "b": {"x": 1}, "c": 3}
override = {"b": None, "c": {"k": 1}}
Output
{"a": 1, "c": {"k": 1}}

None deletes the key; a non-dict override replaces the base dict.

Follow-up

How would you detect and reject cyclic references in input objects?