FunctionRacerProblemsRace

Factorials Up to n

BeginnerDynamic programmingPython, JavaScript, TypeScript, Java, C++

The factorial of a number is the product of all whole numbers from 1 up to it, and the factorial of 0 is 1. So the factorials of 0, 1, 2, 3, 4 are 1, 1, 2, 6, 24.

Return the list of the factorials of 0, 1, 2 and so on up to n. Each one is the one before it times its own number, so nothing has to be multiplied out from scratch.

Example 1

n 4
returns [1,1,2,6,24]

Each entry is the one before it times its position: 6 * 4 = 24.

Example 2

n 0
returns [1]

Only the factorial of 0.

Example 3

n 1
returns [1,1]

The factorials of 0 and 1 are both 1.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Dynamic programming problems