FastPrepIn-Memory Database with TTL
Problems/In-Memory Database with TTL

In-Memory Database with TTL

Autodesk logoAutodesk● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names an in-memory database with TTL and links the canonical cache-with-time-limit exercise. The judged finite operation batch matches it at about 95%.

Build an in-memory key-value database where every entry has a time to live (TTL). You get a list of operations, each with a time now. Times never go down, and operations with the same time happen in list order.

An entry set at time t with TTL d is active while now < t + d. At time t + d it has expired, and an expired entry counts as missing.

OperationWhat to return
["SET", key, value, ttl, now]Store value for key, active until now + ttl. Return true if the key had an active value just before this operation, otherwise false.
["GET", key, now]Return the key's active value, or NULL if it has none.
["COUNT", now]Return how many keys are active.

Every part of every row is a string, numbers included. Return one string per operation, in order.

Function

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

Examples

Example 1

operations = [["SET","a","1","5","0"],["GET","a","4"],["GET","a","5"],["COUNT","5"]]return = ["false","1","NULL","0"]

a is set at time 0 with TTL 5, so it is active while the time is below 5. The SET returns false because a had no value before. At time 4, GET a returns 1. At time 5 it has expired, so GET a returns NULL and COUNT returns 0.

Example 2

operations = [["SET","x","old","10","1"],["SET","x","new","3","4"],["GET","x","6"],["SET","x","fresh","5","7"],["COUNT","7"]]return = ["false","true","new","false","1"]

x = "old" is active from time 1 until 11. At time 4 it is still active, so setting "new" returns true; "new" lasts until 4 + 3 = 7. At time 6, GET x returns "new". At time 7, "new" has just expired, so setting "fresh" returns false. Now only x is active, so COUNT returns 1.

Constraints

  • 1 ≤ operations.length ≤ 200000
  • Keys and values are non-empty ASCII strings. No value is the string NULL.
  • Times are integers from 0 to 10^18, and they never go down from one row to the next.
  • Every TTL is an integer from 1 to 10^18.

More Autodesk interview questions

  • Diagonal Bounce TraversalOA · Seen Oct 2026
  • Interleave Array HalvesOA · Seen Oct 2026
  • Latest Arrival to Catch a BusOA · Seen Oct 2026
  • Find Top Two TeamsOA · Seen Sep 2026
  • Non-Repeating CharacterONSITE INTERVIEW · Seen Nov 2026
  • Remove Trailing ZerosONSITE INTERVIEW · Seen Nov 2026
  • Reverse Linked ListONSITE INTERVIEW · Seen Nov 2026
  • LRU Cache with TTLONSITE INTERVIEW · Seen Oct 2026
  • Deep Merge with a Conflict ResolverONSITE INTERVIEW · Seen Mar 2026

Similar questions at other companies

  • Bank Accounts with Balance HistoryMeta · OAMeta interview questions
  • Corporate Card Expense RulesRippling · OA · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Least Recently Used CacheMicrosoft · OA · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
  • Parcel Event TrackingAirbnb · OAAirbnb interview questions
  • Process Banking OperationsVercel · OA
  • Expiring Authentication Token ManagerIBM · OAIBM interview questions
  • Layer History with Batch Undo and RedoFigma · OA · PHONE SCREENFigma interview questions
  • Event Statistics AggregatorWells Fargo · OAWells Fargo interview questions
  • Temporal Key-Field Database with Prefix ScansThe Trade Desk · OA
  • Per-Client Sliding-Window Rate LimiterGeneral Motors · OA

Autodesk interview experiences

  • Autodesk SDE Intern OA and Interviews: 5 Experiences
All Autodesk interview questionsSee Autodesk hiring insights
Saved
class Solution {
    public String[] runTimedDatabase(String[][] operations) {
        // Write your code here.
    }
}
Checking account…