Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Recursion Over Nested Data
00:00
5 left

Recursion Over Nested Data

MediumPython

Problem

Klaviyo event payloads can contain nested objects and arrays, such as profile properties, product details, and line items. Implement a recursive function that flattens a JSON-compatible payload into a dictionary of paths to scalar values.

Formal Specification

Given payload, a JSON-compatible Python dictionary or list, return a dictionary where:

  1. Each scalar value, including strings, numbers, booleans, and None, becomes one output entry.
  2. Nested dictionary keys are joined with ..
  3. Array elements use zero-based numeric path components.
  4. Empty dictionaries and lists produce no entries.
  5. The input must not be modified.

For example, {"customer": {"email": "a@example.com"}} becomes {"customer.email": "a@example.com"}.

Constraints

  • 1 <= number of contained values <= 10^4
  • Nesting depth is at most 100
  • Dictionary keys are non-empty strings and do not contain .
  • Values follow standard JSON types: object, array, string, number, boolean, or null

Function Signature

def flatten_event_payload(payload):
Interviewer

Your question is Recursion Over Nested Data. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.