Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Flatten Nested Dictionary Keys

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

Your question is Flatten Nested Dictionary Keys. 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

Problem

Given a nested dictionary data, return a new flattened dictionary where each nested key path is joined by .. Leaf values should be preserved as-is. If a value is itself a dictionary, continue flattening it recursively.

Assume keys are strings and values are either dictionaries or terminal values such as integers, strings, booleans, or None. The output should contain one entry for every leaf value in the nested structure.

Constraints

  • 0 <= number of keys in the entire structure <= 10^4
  • Keys are non-empty strings without .
  • Values are either dictionaries or terminal scalar values
  • The nesting depth can be large enough to require recursion or an explicit stack
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output