Time-Based Key-Value Store with Range Aggregates
Updated
Problem statement
Process a sequence of operations on a time-based key-value store. Each key keeps integer values at strictly increasing integer timestamps.
SET key timestamp value: store the value and return"null".GET key timestamp: return the value at the greatest stored timestamp not exceedingtimestamp, or the empty string when no such value exists.SUM key start end: return the sum of values whose timestamps are in the inclusive interval[start, end], or"0"when the interval is empty.AVG key start end: return the arithmetic mean over the same inclusive interval as an exact reduced fraction. Return an integer when the denominator is one, and the empty string when the interval is empty.
Return one string for every operation, in input order.
Function
runTimeStore(operations: String[]) → String[]Examples
Example 1
operations = ["SET cpu 1 10","SET cpu 3 20","GET cpu 2","SUM cpu 1 3","AVG cpu 1 3","GET cpu 0","SUM cpu 4 8","AVG cpu 4 8"]return = ["null","null","10","30","15","","0",""]The lookup at timestamp 2 sees the value 10. Both values lie in [1,3], so the sum is 30 and the average is 15. The remaining queried ranges contain no eligible values.
Example 2
operations = ["SET load 2 -4","SET load 5 7","SET load 9 2","GET load 8","SUM load 3 9","AVG load 2 9","AVG load 5 9"]return = ["null","null","null","7","9","5/3","9/2"]The range [2,9] contains all three values, whose exact average is 5/3. The range [5,9] contains 7 and 2, whose average is 9/2.
Constraints
1 <= operations.length <= 100000.- Every operation has one of the four documented forms.
- Keys contain 1 to 30 lowercase English letters or digits.
0 <= timestamp, start, end <= 10^9andstart <= end.-10^9 <= value <= 10^9.SETtimestamps are strictly increasing for each key.- Every range sum fits in a signed 64-bit integer.
More Confluent Phone Screen questions
- Implement tail -nPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Sudoku Board ValidationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Sudoku Puzzle SolverPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Match a Variadic Function SignaturePHONE SCREEN · Seen Oct 2026
- Sequential Phrase Search Across DocumentsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Time Map with Sum and AveragePHONE SCREEN · Seen Sep 2026
- Word Search Across DocumentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Windowed Key-Value MapPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
- Least-Strong Common DefeaterPHONE SCREEN · Seen Oct 2022
- Wildcard Matching with StarsPHONE SCREEN · Seen Mar 2021
Similar questions at other companies
- Out-of-Order Logger Rate LimiterGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Consistent-Hash Packet RouterAmazon · PHONE SCREEN
- Snapshot Map with Sparse Version HistorySnorkel AI · PHONE SCREEN
- Maintain a Consistent-Hashing RingApple · PHONE SCREENApple interview questions
- Time-Based Key-Value StoreOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
- Time-Based Key-Value StoreCockroach Labs · PHONE SCREEN · ONSITE INTERVIEW
- Structured Log Stream with QueriesOpenAI · PHONE SCREENOpenAI interview questions
- Time-Based Key-Value StoreVerkada · PHONE SCREENVerkada interview questions
- Interview Slot BookingTrueFoundry · PHONE SCREEN
- Time-Based Key-Value Map With Floor and Ceiling QueriesCharacter.AI · PHONE SCREEN
Confluent interview experiences
- Confluent Older Concurrency Rounds: 12 Experiences (Part 2 of 2)
- Confluent Concurrency Interviews: 28 Experiences (Part 1 of 2)
- Confluent SWE OA, Coding and Design Interviews: 19 Experiences
- Confluent File Manipulation Round (tail -n): 19 Experiences
- Confluent Coding and System Design Questions: 33 Questions