Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Map Dictionary Manipulation

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Map Dictionary Manipulation. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Antino Labs mobile configuration is stored as a nested Python dictionary. Implement apply_updates(config, updates) to apply ordered set and delete operations using dot-separated paths.

A set operation must create missing intermediate dictionaries. If an intermediate value is not a dictionary, replace it with an empty dictionary before continuing. A delete operation should do nothing when its path or an intermediate dictionary does not exist. After deletion, remove empty parent dictionaries created by that deletion. The function must not mutate the input config.

Formal Specification

  • config is a dictionary containing JSON-compatible values.
  • updates is a list of dictionaries. Each update has op, which is either "set" or "delete", and path, a non-empty dot-separated string.
  • A set update also contains value, which may be any JSON-compatible value.
  • Return a new dictionary containing the final configuration.
  • Paths always refer to nested dictionary keys and never target the root.

Constraints

  • 1 <= len(updates) <= 10^4
  • 1 <= number of path segments <= 20
  • Keys are non-empty strings without dots
  • Values contain at most 10^4 total nested entries
  • Updates are applied in the given order

Function Signature

def apply_updates(config, updates):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output