Key-Value Store GET and PUT QPS
Updated
Problem statement
Implement a key-value store that reports separate GET and PUT request rates over the trailing 300 seconds.
The function receives the server start time and a finite list of operations. Operations use nondecreasing integer-second timestamps and are processed in input order:
PUT|t|key|valuestores or overwrites a string value and produces no output.GET|t|keycounts as a GET and producesVALUE:valuewhen the key exists orNULLotherwise.GET_LOAD|tcounts as neither GET nor PUT and producesGET:a/b|PUT:c/d.
For a load query at time t, count requests in the half-open interval (t - 300, t]. Divide each count by min(t - serverStartTime, 300). Every GET_LOAD timestamp is strictly greater than the server start time. Write each fraction in lowest terms with a positive denominator; write zero as 0/1.
A request at the same timestamp as a GET_LOAD is included only when it appears earlier in the input.
Function
runLoadAwareStore(serverStartTime: long, operations: String[]) → String[]Examples
Example 1
serverStartTime = 0operations = ["PUT|1|a|x","GET|2|a","GET|2|missing","GET_LOAD|3","GET_LOAD|301"]return = ["VALUE:x","NULL","GET:2/3|PUT:1/3","GET:1/150|PUT:0/1"]The first load uses three seconds of uptime. At time 301, the PUT at time 1 is outside (1, 301], while both GET requests at time 2 remain in the window.
Constraints
0 <= serverStartTime <= 10^91 <= operations.length <= 200000- Operation timestamps are in
[serverStartTime, 10^9]and are nondecreasing. - Every GET_LOAD time is greater than
serverStartTime. - Keys and values contain 1 to 40 ASCII letters, digits, underscores, or hyphens.
More Databricks Phone Screen questions
- Rolling Hit CounterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Minimize CommuteOA · PHONE SCREEN · Seen Oct 2026
- Top-K Values per Key in MapReducePHONE SCREEN · Seen Oct 2026
- Customer Revenue with Direct ReferralsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- File Encryption Tree OptimizationPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Encrypted File Count and Minimum TimePHONE SCREEN · Seen Sep 2026
- Circuit Breaker Database FailoverPHONE SCREEN · Seen Aug 2026
- Find First Anagram IndexPHONE SCREEN · Seen Aug 2026
- Ordered IP FirewallPHONE SCREEN · Seen Aug 2026
- Snapshot Set IteratorPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
Similar questions at other companies
- Completions API Rate LimiterCursor · PHONE SCREENCursor interview questions
- Per-Client Sliding-Window Rate LimiterGeneral Motors · OA
- Metric Counter with a Fake ClockSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
- Per-Client Sliding-Window Rate LimiterNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
- 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Dynamic Least-Loaded Job DispatcherCresta · PHONE SCREENCresta interview questions
- Windowed Key-Value MapConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
- Rate Limiter with a Sliding Window per ClientStackAdapt · PHONE SCREENStackAdapt interview questions
- Per-Client API Rate LimiterDocker · PHONE SCREEN
- Per-Client Sliding-Window Rate LimiterCVS Health · PHONE SCREEN