Created
August 26, 2025 02:23
-
-
Save pbdeuchler/cbca971b962e9a461823d902cf70b243 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | |
| Function signature to expose: | |
| function lruops( | |
| ops: [op: string, key: number, value?: number][], | |
| capacity: number, | |
| ): number[] | |
| Constraints: | |
| 1 ≤ capacity ≤ 10^4 | |
| |ops| ≤ 10^4 | |
| Examples: | |
| lruops([[["put",1,1],["get",1]]], 1) // -> [1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment