FastPrepClosest-Timestamp Key-Value Queries
Problems/Closest-Timestamp Key-Value Queries

Closest-Timestamp Key-Value Queries

Google logoGoogle● MediumINTERNPHONE SCREEN

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: PhD Intern — The firsthand Google internship report says the task combines a time-based key-value store with closest-value lookup. FastPrep keeps the timestamped per-key state and interprets the closest lookup as the stored value at the timestamp nearest to each query, with an earlier-timestamp tie rule.

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 <= 200000
  • entryKeys.length == entryTimes.length == entryValues.length
  • 1 <= queryKeys.length == queryTimes.length <= 200000
  • Keys and values contain 1 to 40 printable 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

Interview reports that mention this question

  • Google SWE and PhD Intern Coding: 14 Experiences (Part 3 of 3)

Google interview experiences

  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
  • Google AI Coding Interview and AI OA: 2 Experiences
  • Google SWE Intern Interview Results Timeline: 13 Experiences
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public String[] closestValues(String[] entryKeys, int[] entryTimes, String[] entryValues, String[] queryKeys, int[] queryTimes) {
        // Write your code here.
    }
}
Checking account…