Compute an Exact Factorial
Company: Wayve
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Technical Screen
Quick Answer: Implement exact factorial for nonnegative n up to 1,000, including the zero case. The result may exceed fixed-width integer ranges, and the implementation should not depend on deep recursion.
Constraints
- 0 <= n <= 1,000
- Return the exact decimal representation of n!.
- Do not rely on recursion depth.
Examples
Input: (0,)
Expected Output: '1'
Explanation: Checks the exact decimal factorial, including 0! and values beyond fixed-width ranges.
Input: (1,)
Expected Output: '1'
Explanation: Checks the exact decimal factorial, including 0! and values beyond fixed-width ranges.
Hints
- Start with 1 and multiply by each integer from 2 through n.
- Use a big-integer type or a decimal limb array where fixed-width multiplication would overflow.