Closest-Timestamp Key-Value Queries
Updated
Problem statement
You receive timestamped key-value entries through parallel arrays. Entry i stores entryValues[i] for entryKeys[i] at entryTimes[i]. For each individual key, its timestamps appear in strictly increasing order, although entries for different keys may be interleaved.
For every pair (queryKeys[i], queryTimes[i]), return the value stored for that key at the timestamp closest to the query time. If the closest timestamps on the two sides are equally far away, choose the earlier timestamp. Return the empty string when the key has no stored entry.
Function
closestValues(entryKeys: String[], entryTimes: int[], entryValues: String[], queryKeys: String[], queryTimes: int[]) → String[]Examples
Example 1
entryKeys = ["a","b","a","a","b"]entryTimes = [1,2,5,9,8]entryValues = ["one","bee2","five","nine","bee8"]queryKeys = ["a","a","b","c"]queryTimes = [7,3,6,4]return = ["five","one","bee8",""]For key a, time 7 ties between 5 and 9, so time 5 wins. Time 3 is closer to 1 than 5. For key b, time 8 is closer than 2. Key c is absent.
Example 2
entryKeys = ["x","x"]entryTimes = [10,20]entryValues = ["old","new"]queryKeys = ["x","x"]queryTimes = [5,25]return = ["old","new"]A query before all entries chooses the first timestamp, and a query after all entries chooses the last timestamp.
Constraints
0 <= entryKeys.length <= 200000entryKeys.length == entryTimes.length == entryValues.length1 <= queryKeys.length == queryTimes.length <= 200000- Keys and values contain
1to40printable ASCII characters. 0 <= entryTimes[i], queryTimes[i] <= 1000000000.- For each key, entry timestamps are strictly increasing in encounter order.
More Google Phone Screen questions
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026
- Minimum Total Layover WaitPHONE SCREEN · Seen Nov 2026
- Reach a Destination Through Scheduled FlightsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Snapshot Map with Sparse Version HistorySnorkel AI · PHONE SCREEN
- Time-Based Key-Value StoreOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
- Time-Based Key-Value StoreCockroach Labs · PHONE SCREEN · ONSITE INTERVIEW
- Time Map with Sum and AverageConfluent · PHONE SCREENConfluent interview questions
- 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
- Versioned Document StoreNotion · PHONE SCREENNotion interview questions
- Simplified Time-Based Key-Value StoreSpaceX · PHONE SCREENSpaceX interview questions