Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Python Key-Value Program

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

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

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output