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

Programming Exercises

Write a function that memoizes another function to improve performance.

Hard

Problem Statement

Write a function that memoizes another function to improve performance.

Sample Input

Function to be memoized: fibonacci
Argument for the memoized function: 10

Sample Output

55

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
// Memoize a function to improve performance function memoize(fn) { // Create a cache object // Return a function that checks if the result is in the cache // If not, calculate, store, and return the result } // Example function to memoize function fibonacci(n) { // Base cases for fibonacci // Recursive call for fibonacci sequence } const memoizedFibonacci = memoize(fibonacci); console.log(memoizedFibonacci(10));
Log in or sign up to run or submit your code.Log inSign up
Input
Function to be memoized: fibonacci
Argument for the memoized function: 10
Expected Output
55