Memoize One-Argument Function

JavaScript Medium 4 views
Back to Questions

Problem Description

Input has a list of queries for a slow function f(x)=x*x+1. For repeated x, do not recompute; use memoization and print outputs for each query.

Input Format

First line q. Next q lines: x.

Output Format

q lines of f(x).

Sample Test Case

Input:
6 2 3 2 5 3 2
Output:
5 10 5 26 10 5

Constraints

0

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Prev Next