Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Create a function that memoizes the result of a computationally expensive function.

Hard

Problem Statement

Create a function that memoizes the result of a computationally expensive function.

Sample Input

A function f(x) = x * x and input 5 called twice.

Sample Output

Result from computation
25
Result from cache
25

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
function memoize<T, R>(func: (arg: T) => R): (arg: T) => R { // Your logic here }
Log in or sign up to run or submit your code.Log inSign up
Input
A function f(x) = x * x and input 5 called twice.
Expected Output
Result from computation
25
Result from cache
25