Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Flatten Nested JSON Configuration Paths
00:00
5 left

Flatten Nested JSON Configuration Paths

MediumPython

Problem

Celebal Technologies frontend dashboards receive configuration data as nested JSON-like objects. Implement flatten_config to convert every nested dictionary or list value into a single dictionary whose keys use dot-separated paths.

Formal Specification

The input is a JSON-like value containing dictionaries, lists, and primitive values: strings, numbers, booleans, or None. Dictionary keys are non-empty strings that do not contain a dot. A dictionary child uses its key in the path, and a list child uses its zero-based index. Return a dictionary mapping each leaf path to its original value.

Non-empty dictionaries and lists must be recursively expanded. Empty dictionaries and empty lists are treated as leaf values and should be preserved. The root input is always a dictionary. Do not mutate the input.

Constraints

  • 0 <= number of containers and leaves <= 10^4
  • Maximum nesting depth is 100
  • Dictionary keys are non-empty strings without a dot
  • Values are JSON-like: dictionaries, lists, strings, numbers, booleans, or None
  • The root input is always a dictionary
  • The input must not be mutated

Function Signature

def flatten_config(config):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

You need to log in / sign up to run or submit.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.