Factorial Generator - Problem
Write a generator function that takes an integer n as an argument and returns a generator object which yields the factorial sequence.
The factorial sequence is defined by the relation n! = n * (n-1) * (n-2) * ... * 2 * 1. The factorial of 0 is defined as 1.
The generator should yield factorials starting from 0! up to n!.
Input & Output
Example 1 — Basic Case
$
Input:
n = 4
›
Output:
[1, 1, 2, 6, 24]
💡 Note:
Generate factorials from 0! to 4!: 0!=1, 1!=1, 2!=2, 3!=6, 4!=24
Example 2 — Minimum Case
$
Input:
n = 0
›
Output:
[1]
💡 Note:
Only 0! = 1 by definition
Example 3 — Small Sequence
$
Input:
n = 2
›
Output:
[1, 1, 2]
💡 Note:
Generate 0!=1, 1!=1, 2!=2×1=2
Constraints
- 0 ≤ n ≤ 10
- All factorials will fit in 32-bit integer
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code