PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates competency in designing time-indexed in-memory key-value stores, including handling ordered timestamps and achieving efficient lookups through suitable data structures and algorithms.

  • medium
  • Navan
  • Coding & Algorithms
  • Software Engineer

Design time-based key-value store

Company: Navan

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Design an in-memory key-value store that supports time-based lookups. ## Operations Implement a class (or module) with the following methods: 1. `set(key, value, timestamp)` - Stores the string `value` for string `key` at integer `timestamp`. - Multiple values may be stored for the same key at different timestamps. 2. `get(key, timestamp)` - Returns the value associated with `key` for the **largest stored timestamp `t` such that `t <= timestamp`**. - If there is no such timestamp for the key, return an empty string (or `null`, but be consistent). ## Notes / Constraints - Timestamps for `set()` calls on the same key are non-decreasing. - Aim for efficient `get()` queries. - You may assume ASCII strings for keys/values. ## Example - `set("room", "A", 10)` - `set("room", "B", 20)` - `get("room", 5) -> ""` - `get("room", 10) -> "A"` - `get("room", 15) -> "A"` - `get("room", 20) -> "B"` - `get("room", 25) -> "B"`

Quick Answer: This question evaluates competency in designing time-indexed in-memory key-value stores, including handling ordered timestamps and achieving efficient lookups through suitable data structures and algorithms.

Process set/get operations and return values at the largest timestamp not greater than the query timestamp.

Constraints

  • Set timestamps for the same key are non-decreasing

Examples

Input: ((('set', 'room', 'A', 10), ('set', 'room', 'B', 20), ('get', 'room', 5), ('get', 'room', 10), ('get', 'room', 15), ('get', 'room', 25)),)

Expected Output: ['', 'A', 'A', 'B']

Explanation: Prompt example.

Input: ((('get', 'x', 1),),)

Expected Output: ['']

Explanation: Missing key.

Input: ((('set', 'k', 'a', 1), ('set', 'k', 'b', 1), ('get', 'k', 1)),)

Expected Output: ['b']

Explanation: Same timestamp returns latest inserted by tuple order/value semantics.

Hints

  1. Store sorted timestamp/value pairs per key and binary-search on get.
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
  • AI Coding 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.