Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Merge two JSON-like config dicts with overrides

Python data engineering interview problem. Difficulty: intermediate. Pattern: Dictionaries. About 15 minutes. Part of the Pro drill bank.

Service config is a nested dict. A deploy overlay should override matching keys and leave unspecified keys from the base intact, including nested maps.

Merge two JSON-like dicts so overlay keys win, recursively for nested dicts.

Requirements

  • Nested dicts merge recursively.
  • Non-dict override values replace the base value.

Constraints

  • base and override: nested dictionaries.
  • Do not flatten lists unless tests say so.

Examples

Input: deep_merge({'a': 1, 'b': {'c': 2}}, {'b': {'d': 3}, 'e': 4}) Output: {'a': 1, 'b': {'c': 2, 'd': 3}, 'e': 4} This input follows the stated rules and produces this output.

Topics: lakebench, python, JSON-like-data.

More Python interview questions · All interview problems · Learn data engineering

intermediate

Merge two JSON-like config dicts with overrides

Interview-style drill: Merge a base config dict with an override dict, letting override values win at every nesting level.

Merge two JSON-like dicts so overlay keys win, recursively for nested dicts.