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 Threaded Comments
00:00
5 left

Flatten Threaded Comments

MediumPython

Problem

Tell me about how you would flatten a nested dictionary structure into a flat list format like a: 1, b: c: 2, b: d: 3.

Implement flatten_dict(data) to return one string for each leaf value, preserving dictionary insertion order. Nested keys must be joined with : , and empty dictionaries produce no output.

Input is a dictionary whose values are either scalar values or dictionaries. Output is a list of strings such as ["a: 1", "b: c: 2", "b: d: 3"].

Constraints

  • 1 <= total number of dictionary entries <= 10000
  • Maximum nesting depth is 1000
  • Keys are strings
  • Each value is either a dictionary or a scalar JSON-compatible value
  • Return one output string for every scalar leaf
  • Preserve insertion order and use : between path components

Function Signature

def flatten_dict(data):
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.