PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates understanding of time-versioned data structures, temporal indexing, and efficient lookup strategies for storing and retrieving values by key across timestamps.

  • medium
  • Microsoft
  • Coding & Algorithms
  • Software Engineer

Design a Versioned Key-Value Store

Company: Microsoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Implement a data structure for storing values by key over time. The structure should support these operations: - `put(key, value, timestamp)`: Store the string `value` for the string `key` at the given integer `timestamp`. - `get(key, timestamp)`: Return the value associated with `key` at the greatest timestamp less than or equal to `timestamp`. If there is no stored value for `key` at or before the requested time, return an empty string. Assumptions: - `key` and `value` are non-empty strings. - `timestamp` is a positive integer. - Calls to `put` are given in strictly increasing timestamp order. Example: - `put("foo", "bar", 1)` - `get("foo", 1)` returns `"bar"` - `get("foo", 3)` returns `"bar"` - `put("foo", "baz", 4)` - `get("foo", 4)` returns `"baz"` - `get("foo", 5)` returns `"baz"`

Quick Answer: This question evaluates understanding of time-versioned data structures, temporal indexing, and efficient lookup strategies for storing and retrieving values by key across timestamps.

Implement solution(operations). Operations are ["put", key, value, timestamp] and ["get", key, timestamp]. For get, return the value at the greatest timestamp <= the query timestamp, or the empty string if none exists. Return all get results in order.

Constraints

  • put timestamps are strictly increasing
  • keys and values are strings

Examples

Input: ([['put', 'foo', 'bar', 1], ['get', 'foo', 1], ['get', 'foo', 3], ['put', 'foo', 'baz', 4], ['get', 'foo', 4], ['get', 'foo', 5], ['get', 'x', 5]],)

Expected Output: ['bar', 'bar', 'baz', 'baz', '']

Input: ([['put', 'a', 'x', 2], ['put', 'a', 'y', 5], ['get', 'a', 4], ['get', 'a', 5]],)

Expected Output: ['x', 'y']

Hints

  1. Store sorted (timestamp, value) lists per key and binary-search them.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Return Top K Open Businesses - Microsoft (hard)
  • Implement Memory Allocation and In-Memory Records - Microsoft (medium)
  • Sort Three Categories In Place - Microsoft (medium)
  • Implement K-Means and Detect Divisible Subarrays - Microsoft (medium)
  • Retain Top K Elements - Microsoft (medium)