FastPrepIn-Memory Database with Historical Field Lookup
Problems/In-Memory Database with Historical Field Lookup

In-Memory Database with Historical Field Lookup

Meta logoMeta● HardFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report explicitly combines get, set, delete and TTL with key-and-field get_when queries, using version start/end timestamps rather than whole-database rollback. This exercise authors a finite string-row operation format, query-only output, numeric bounds, zero-TTL convention and exact half-open endpoints. Historical timestamp zero is an ordinary time, not a special current-read alias. Approximate source match: 97%.

Maintain an initially empty in-memory database addressed by a pair (key, field). Process operations in their given order. Every row has string arguments, and operation timestamps t are strictly increasing.

  • ["SET", t, key, field, value, ttl]: write the nonnegative integer value. A positive TTL makes it visible on [t, t + ttl); a TTL of zero means it does not expire automatically. An overwrite immediately ends the previous version, even if the new value later expires.
  • ["DELETE", t, key, field]: remove the current value, if one exists. It is absent from t onward until another set. Deleting an absent or expired field is a no-op.
  • ["GET", t, key, field]: return the value visible at the current time t.
  • ["GET_WHEN", t, key, field, at]: return the value that was visible at historical time at, where 0 <= at <= t.

Return one string per GET or GET_WHEN, in query order: the decimal value, or the exact string "NULL" if the field was absent. Sets and deletes produce no output.

Overwriting or deleting a field does not erase its earlier history. A version ends at the earliest of its expiration, the next overwrite, or the next deletion. The start is inclusive and the end is exclusive. Once a version ends, it never reappears. Different key-and-field pairs are independent.

A historical query is read-only; it does not roll back the database or change later queries. Historical time 0 means the actual timestamp zero. All numeric strings are canonical nonnegative decimal integers with no leading zeros except "0".

Function

historicalFieldValues(operations: String[][]) → String[]

Examples

Example 1

operations = [["SET","1","a","x","10","0"],["SET","5","a","x","20","5"],["GET_WHEN","6","a","x","2"],["GET_WHEN","7","a","x","5"],["GET","10","a","x"],["GET_WHEN","11","a","x","9"],["DELETE","12","a","x"],["GET_WHEN","13","a","x","4"]]return = ["10","20","NULL","20","10"]

The first version is valid on [1,5) and the second on [5,10). The current read at time 10 is absent, while historical reads at 9 and 4 still recover their respective values.

Example 2

operations = [["SET","0","a","x","7","0"],["SET","2","a","y","8","0"],["DELETE","4","a","x"],["GET_WHEN","5","a","x","3"],["GET","6","a","x"],["GET","7","a","y"],["GET_WHEN","8","a","y","0"]]return = ["7","NULL","8","NULL"]

Deleting field x does not affect field y or erase the earlier value of x. Field y did not exist at historical time zero.

Constraints

  • 0 <= operations.length <= 200.
  • Every row has exactly the arguments specified by its operation name.
  • 0 <= t, value, ttl <= 1000000000; operation timestamps are strictly increasing.
  • Every historical time satisfies 0 <= at <= t.
  • Keys and fields each contain 1 through 10 lowercase English letters.
  • Expiration times may exceed the maximum operation timestamp, so use a sufficiently wide integer type.

More Meta interview questions

  • Cave AdvantureOA · Seen May 2024
  • Closest Land Mark 👏OA · Seen Feb 2024
  • Count Events in Rolling Minute WindowsPHONE SCREEN · Seen Oct 2026
  • Valid Word AbbreviationPHONE SCREEN · Seen Oct 2026
  • Shortest Path in a Binary MatrixPHONE SCREEN · Seen Sep 2026
  • Deterministic K-Means AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Linear Layer Forward and Backward PassesONSITE INTERVIEW · Seen Sep 2026
  • Reservoir Sampling with Recorded DrawsONSITE INTERVIEW · Seen Sep 2026
  • Stochastic Gradient Descent with MomentumONSITE INTERVIEW · Seen Sep 2026
  • Top K Largest Values with a HeapONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Banking System with Historical SnapshotsCoinbase · OACoinbase interview questions
  • Out-of-Order Bank Ledger BalancesPerplexity AI · OAPerplexity AI interview questions
  • Time Based Key-Value StoreCoalition · OA
  • Time Based Key-Value StoreAtlassian · OAAtlassian interview questions
  • Versioned Social NetworkOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Out-of-Order Logger Rate LimiterGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • 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

Meta interview experiences

  • Meta AI-Native Coding Interview: 3 Experiences
  • Meta Production Engineer Intern Questions: 6 Experiences
All Meta interview questionsSee Meta hiring insights
Saved
class Solution {
    public String[] historicalFieldValues(String[][] operations) {
        // Write your code here
    }
}
Checking account…