Point-in-Time Fare Rule Store Keyed by City and Timestamp

Last updated: November 29, 2026

Quick Overview

Design a store with set(city, rule, timestamp) and get(city, timestamp) that returns the rule that was in effect at that time, meaning the value set with the largest timestamp at or before the query, or an empty string if none.

Uber
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Design a store with set(city, rule, timestamp) and get(city, timestamp) that returns the rule that was in effect at that time, meaning the value set with the largest timestamp at or before the query, or an empty string if none.

An Uber technical screen problem drawn from auditing which pricing rule applied to a past trip, for example in fare disputes. It checks per-key sorted histories and binary search, plus how you would handle out-of-order writes.

What the Interviewer Expects
  • Keeps a per-city list of (timestamp, rule) pairs
  • Uses binary search for the latest timestamp at or before the query
  • Relies on increasing timestamps for O(1) appends, and says what to do if they are not
  • Returns empty for queries before the first write
  • States O(log n) get and O(1) amortized set
Key Topics to Cover
design a data structure
binary search
versioned key-value store
bisect
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if writes arrive out of timestamp order?
  • How would you expire history older than 90 days?
  • How would you persist this so it survives restarts and scales across cities?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • set(city, rule, ts): record a rule version; timestamps per city are strictly increasing.
  • get(city, ts): rule with greatest timestamp <= ts, else "".
  • Many reads per write....
High-Level Design

Map each city to two parallel lists: timestamps and rules. Because timestamps per city increase, set appends to the end. get runs bisect_right on the timestamp list to find the first timestamp g...


Submit Your Answer
Markdown supported