Browse and switch challenges
LRU Cache

Simulate a Least Recently Used (LRU) cache and return the results of get operations. Evictions remove the least-recently-used entry.

An LRU cache is a fixed-capacity key-value store commonly used in web servers, databases, and mobile apps to keep frequently accessed items in memory. When the cache is full and a new item is inserted, the item that hasn't been used for the longest time is evicted. get(key) reads a value (and marks it as most recently used); put(key, value) inserts or updates a value.

Signature
Constraints
  • -1 ≤ capacity ≤ 10^4
  • -|ops| ≤ 10^4
Examples
    System prompt
    0 tokens
    Read-only
    // Waiting for generated code…
    // Your output will appear here as soon as the model returns JavaScript.
    // It must define function lruops(…).
    // Tip: write a prompt on the left and click "Generate code" .
    0 tokens
    Submission #1
    0tokens(0/0)
    Leaderboard
    Loading leaderboard...