FastPrepLRU Cache with TTL
Problems/LRU Cache with TTL

LRU Cache with TTL

Autodesk logoAutodesk● HardFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Autodesk full-time onsite interview. The report gives GET, SET, DELETE, LRU eviction, TTL, edge cases, and many users at once. We chose these: a batch of operations run one after another, the exact moment an entry expires, the result tokens, and the supported limits. Our version is about 93% the same as the reported question.

Process a linearized history for a least-recently-used cache with a fixed positive capacity and per-entry time-to-live values.

  • SET key value ttl timestamp inserts or replaces an entry, makes it most recently used, and returns OK. The entry expires at timestamp + ttl.
  • GET key timestamp returns the stored integer as text and makes the entry most recently used, or returns MISS.
  • DELETE key timestamp removes a live entry and returns DELETED, or returns MISS.

An entry is expired when the operation timestamp is greater than or equal to its expiration time. Remove expired entries before each operation. When a set leaves too many live entries, evict the least recently used one. Return one result string per command.

Function

runLruCache(capacity: int, commands: String[]) → String[]

Examples

Example 1

capacity = 2commands = ["SET a 1 5 0","SET b 2 10 1","GET a 2","SET c 3 10 3","GET b 4","GET a 5","DELETE c 6","GET c 7"]return = ["OK","OK","1","OK","MISS","MISS","DELETED","MISS"]

The access to a makes it newer than b, so setting c evicts b. Entry a expires exactly at timestamp 5.

Example 2

capacity = 1commands = ["SET x 4 3 0","GET x 2","GET x 3"]return = ["OK","4","MISS"]

The entry is live before timestamp 3 and expired at timestamp 3.

Constraints

  • capacity is between 1 and 1000.
  • The command list contains between 1 and 2000 rows.
  • Each command contains between 5 and 100 characters.
  • Commands use SET key value ttl timestamp, GET key timestamp, or DELETE key timestamp; keys contain no spaces, values are integers that fit in signed 64-bit integers, TTL values are between 1 and 1012, timestamps are between 0 and 1012 and are nondecreasing, and every expiration timestamp is at most 2 × 1012.

Source note: Author-written prompt excerpt retained for source fidelity.

More Autodesk interview questions

  • Deep Merge with a Conflict ResolverONSITE INTERVIEW · Seen Mar 2026
  • 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
  • In-Memory Database with TTLOA · Seen Mar 2026

Similar questions at other companies

  • LFU CacheAmazon · ONSITE INTERVIEW
  • LFU CacheSnowflake · OA · ONSITE INTERVIEWSnowflake interview questions
  • 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Recover a Function-Call LRU Cache with a Write-Ahead LogAnthropic · ONSITE INTERVIEWAnthropic interview questions
  • LFU CacheSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Tiered Expiring Item StoreHudson River Trading · PHONE SCREEN · ONSITE INTERVIEWHudson River Trading interview questions
  • LFU CacheBlinkit · ONSITE INTERVIEWBlinkit interview questions
  • Thread-Safe LRU Cache with TTLLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Fair Multi-Tenant CacheOkta · ONSITE INTERVIEWOkta interview questions
  • LFU CacheZomato / Eternal · ONSITE INTERVIEWZomato / Eternal interview questions

Autodesk interview experiences

  • Autodesk SDE Intern OA and Interviews: 5 Experiences
All Autodesk interview questionsSee Autodesk hiring insights
Saved
class Solution {
    public String[] runLruCache(int capacity, String[] commands) {
        // Write your code here.
    }

}
Checking account…