Closures & Functions

Memoize with Time-To-Live (TTL)

mediumJS SpecificJS / TS3 tests

Problem Statement

Implement `memoizeWithTTL(fn, ttlMs)` that caches the results of function calls for `ttlMs` milliseconds based on serialized arguments. When the TTL expires for a cached key, calling the function again re-evaluates `fn`.

Examples

Example 1:
let calls = 0;
const add = memoizeWithTTL((a, b) => { calls++; return a + b; }, 100);
add(1, 2); // 3 (calls = 1)
add(1, 2); // 3 (cached, calls = 1)
JavaScript & TypeScript starter code included
Run this as a live interview

Practice solo

3 test cases. No second person needed.

Get new interview exercises

Practice problems and review drills, sent when we publish new ones. No spam.

Unsubscribe anytime. We never share your address.