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
Python Key-Value Program
00:00
5 left

Python Key-Value Program

MediumPython

Problem

Beyondsoft configuration rollout tooling records key-value updates over time. Given the update history and a set of query timestamps, return the complete configuration snapshot visible at each query time.

An update is represented as [timestamp, key, value]. Timestamps are integers and are not necessarily provided in sorted order. If value is null, the key is deleted. Every update with timestamp <= query_timestamp must be applied before producing that query's snapshot. Query results must remain in the same order as the input queries.

Formal Specification

Implement reconstruct_snapshots(operations, queries).

  • operations is a list of lists, where each item contains an integer timestamp, a string key, and either a string value or null.
  • queries is a list of integer timestamps.
  • Return a list of dictionaries. The item at index i contains the key-value state at queries[i].
  • The returned snapshots must be independent dictionaries, so later updates must not change earlier results.

Constraints

  • 0 <= len(operations), len(queries) <= 10^5
  • 0 <= timestamp <= 10^9
  • 1 <= len(key) <= 50
  • Values are strings of length at most 100, or null
  • Keys and timestamps may repeat

Function Signature

def reconstruct_snapshots(operations, queries):
Interviewer

Your question is Python Key-Value Program. 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.