Loading problem…
This problem builds on memoization. Complete that first, then load your solution to continue.
Implement a memoize function with LRU (Least Recently Used) cache that limits cache size and evicts least recently used entries.
fn and cache size limitconst expensiveFn = (n) => n * 2;
const memoized = memoize(expensiveFn, 3);
memoized(1); // Cache: [1]
memoized(2); // Cache: [1, 2]
memoized(3); // Cache: [1, 2, 3]
memoized(4); // Cache: [2, 3, 4] (evicts 1, least recently used)
memoized(2); // Cache: [3, 4, 2] (moves 2 to end)