Look Up the FX Rate in Effect at a Charge Timestamp

Last updated: November 29, 2026

Quick Overview

Build a store of currency conversion rates where each rate for a currency pair has an effective timestamp. Support adding rates in any order and querying the rate that was in effect for a pair at a given time.

Stripe
Coding & Algorithms
Software Engineer
Stripe
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Build a store of currency conversion rates where each rate for a currency pair has an effective timestamp. Support adding rates in any order and querying the rate that was in effect for a pair at a given time.

Stripe settles charges in many presentment and settlement currencies, and refunds or disputes must be converted with the rate that applied when the original charge happened, not today's rate. The interviewer checks that you choose a sorted structure per pair, use binary search correctly for a predecessor query and avoid floating-point money.

What the Interviewer Expects
  • Partition data by currency pair so each query touches one sorted list
  • Use a predecessor search (`bisect_right` minus one) to find the latest rate at or before the timestamp
  • Return a clear result (None) when no rate existed yet
  • Keep rates as `Decimal` rather than float
  • Decide what happens when the same pair and timestamp are inserted twice
Key Topics to Cover
binary search
ordered sets
predecessor query
currency conversion
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
  • How would you make inserts O(log n) instead of O(n) for very long histories?
  • How would you derive a rate for a pair you do not store directly, such as via USD?
  • How would you serve this from a cache shared across many API servers?
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

add(base, quote, effective_ts, rate) records a rate. get(base, quote, ts) returns the rate whose effective_ts is the largest value <= ts, or None if the first rate starts later. Re-adding th...

High-Level Design

Keep a dict from (base, quote) to two parallel sorted lists: timestamps and rates. Insert with bisect_left, overwrite on an exact timestamp match, otherwise insert at that position. Query with `...


Submit Your Answer
Markdown supported